Angular 2:有多个依赖的组件
Angular 2: component with more than one dependency
以下代码:
...
@Component({
selector: 'sitelink',
properties: ['route: route, title: title, isHome: home, href: href']
})
@View({
template: ''
})
export class SiteLink {
constructor(@Optional() @Host() @SkipSelf() parentFrame: AppFrame, @Optional() @Host() @SkipSelf() parentLink: SiteLink) {
}
...
在从TypeScript到JavaScript的转换过程中给了我以下错误
at line 32, file app-frame.ts Argument of type 'typeof SiteLink' is not assignable to parameter of type 'Type'.
Component({
selector: 'sitelink',
properties: ['route: route, title: title, isHome: home, href: href']
})
at line 36, file app-frame.ts Argument of type 'typeof SiteLink' is not assignable to parameter of type 'Type'.
View({
template: ''
})
只使用一个构造函数参数就可以正常工作。当从参数列表中删除注释时,它也不起作用。删除@Component
和@View
注释后,代码编译。因此,误差一定与@Component
标注有关。编辑:即使我用另一种类型(例如AppFrame)替换SiteLink参数,我也会得到相同的错误。
我使用的是alpha 36和DefinitelyTyped存储库中的最新d.ts文件。
可以通过使用前向引用在构造函数中注入类本身的实例:
constructor(@Inject(forwardRef(() => SiteLink)) siteLink) {
this.name = nameService.getName();
}
正如Jesse Good所写的,这是angular的d.ts文件的一个问题,参见https://github.com/angular/angular/issues/3972.
替换 interface Type extends Function {
new(args: any): any;
}
interface Type extends Function {
new(...args): any;
}
相关文章:
- React重新渲染但未显示正确的组件
- 不能从angular2中的子组件指定父组件中的数组
- 拨打'父亲'函数形式a'儿童'ReactJS中的组件
- 如何正确处理依赖ViewChild和Angular 2中可观察到的数据的组件上的更改检测
- requirejs+bower,bower组件中的路径和依赖关系
- 管理web组件的依赖关系;JS、CSS/SASS和模板文件
- 如何在不让web组件的原型进入全局命名空间的情况下维护它们之间的依赖关系
- 当登录状态为组件状态时,如何使用react路由器实现依赖登录的路径
- 您如何处理 Angular2 中嵌套组件的依赖关系
- 如何处理 React 嵌套组件循环依赖?(使用 es6 类)
- 在 Angular 2 中为路由的通用组件提供异步依赖项.路由的解析等效项
- 在Angular2中添加一个依赖于组件名的外部Javascript文件
- 通过路由依赖注入将angularjs应用拆分为多个组件
- 使用ocLazyLoad插件加载组件和其他依赖项
- React js组件依赖
- 在React中,组件之间传递依赖的正确方式是什么?
- Angular 2:有多个依赖的组件
- Angular2在运行时将AppModule中的服务注入到依赖的ngmodule的组件中
- 如何在不使用组件时使用浏览器化管理依赖项
- ReactJS:组件之间的关系(依赖关系)