Angular 4 无法绑定到 <property>因为它不是 <component> 的已知属性. [英] Angular 4 Can't bind to <property> since it isn't a known property of <component>
本文介绍了Angular 4 无法绑定到 <property>因为它不是 <component> 的已知属性.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在 Angular 4 中创建自己的指令.但是,在将类的属性绑定到组件模板时出现此错误.
I'm trying to create my own directive in Angular 4. But, I got this error when bind the property of class into component template.
控制台错误:
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:
My tree-view-component.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
Here is my complete script file: https://pastebin.com/hDyX2Kjj
有人知道吗?亚安
推荐答案
每个组件、指令和管道都需要在 @NgModule()
Every component, directive, and pipe needs to be registered in @NgModule()
@NgModule({
declarations: [TreeViewComponent]
})
export class AppModule {}
更多详情见
- https://angular.io/api/core/NgModule
- https://angular.io/guide/ngmodules
- https://angular.io/guide/ngmodule-api
这篇关于Angular 4 无法绑定到 <property>因为它不是 <component> 的已知属性.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文