我正在尝试在 Angular 4 中创建自己的指令。但是,在将类的属性绑定到组件模板中时出现此错误。
控制台错误:
Unhandled Promise rejection: Template parse errors: Can't bind to
'data' since it isn't a known property of 'tree'. ("<tree [ERROR
->][data]="data"></tree>"):
我的树视图组件.ts:
@Component({
selector: 'app-tree-view',
template: '<tree [data]="data"></tree>'
})
export class TreeViewComponent implements OnInit {
@Input() data: any[];
constructor() {
this.data = [
{
label: 'a1',
subs: [
{
label: 'a11',
subs: [
{
label: 'a111',
subs: [
{
label: 'a1111'
},
{
label: 'a1112'
}
]
},
{
label: 'a112'
}
]
},
{
label: 'a12',
}
]
}
];
}
ngOnInit() { }
}
这是我的完整脚本文件:https://pastebin.com/hDyX2Kjj https://pastebin.com/hDyX2Kjj
有没有人知道这件事?钛酸化
每个组件、指令和管道都需要注册在@NgModule()
@NgModule({
declarations: [TreeViewComponent]
})
export class AppModule {}
欲了解更多详情,请参阅
- https://angular.io/api/core/NgModule https://angular.io/api/core/NgModule
- https://angular.io/guide/ngmodules https://angular.io/guide/ngmodules
- https://angular.io/guide/ngmodule-api https://angular.io/guide/ngmodule-api
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)