2017-09-06 113 views
0

我在我的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文件中。

+0

您可以編寫自己的解決方案作爲答案並接受它。這將避免混淆。 – TimeTraveler

回答

0

解決

我解決了正確的文件移動進口。我的應用程序有一個用於導入模塊的自定義文件,所以它需要在這裏放置導入,而不是放在app.module文件中。

1

請務必在您的組件中導入Tree。 例如:

import { Tree, TreeNode } from 'primeng/primeng'; 
+0

沒有改變...同樣的錯誤 – bigskull

相關問題