我在我的Angular2 webapp中使用PrimeNG,并且想要使用p-tree组件。 我进口TreeModule在app.module:PrimeNG p-tree错误:由于它不是'p-tree'的已知属性,因此无法绑定到'value'
import { TreeModule } from 'primeng/primeng';
@NgModule({
imports: [
TreeModule,
...
]
})
我的部分是:
import { TreeNode } from 'primeng/primeng';
...
export class MyComponent implements OnInit {
treeNode: TreeNode[];
ngOnInit() {
//Simple value for test p-tree
this.treeNode = [
{
"label": "Documents: " + this.doc,
},
{
"label": "Documents: " + this.doc,
"children": [{
"label": "Work",
},
{
"label": "Home",
}]
}
]
}
}
最后,在HTML:
<p-tree [value]="treeNode"></p-tree>
的错误是:
zone.js:569 Unhandled Promise rejection: Template parse errors:
Can't bind to 'value' since it isn't a known property of 'p-tree'.
1. If 'p-tree' is an Angular component and it has 'value' input, then verify that it is part of this module.
2. If 'p-tree' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. (<p-tree [ERROR ->][value]="treeNode"></p-tree>)
'p-tree' is not a known element:
1. If 'p-tree' is an Angular component, then verify that it is part of this module.
2. If 'p-tree' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. (
[ERROR ->]<p-tree [value]="treeNode"></p-tree>
)
Task: Promise.then ; Value: Error: Template parse errors:
Can't bind to 'value' since it isn't a known property of 'p-tree'.
1. If 'p-tree' is an Angular component and it has 'value' input, then verify that it is part of this module.
2. If 'p-tree' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.
3. To allow any property add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. (<p-tree [ERROR ->][value]="treeNode"></p-tree>)
我发现类似但我找不到一个好的解决方案。 你能帮我吗? 非常感谢。
解决
我解决了正确的文件移动进口。我的应用程序有一个用于导入模块的自定义文件,所以它需要在这里放置导入,而不是放在app.module文件中。
您可以编写自己的解决方案作为答案并接受它。这将避免混淆。 – TimeTraveler