繁体   English   中英

PrimeNG p-tree 错误:无法绑定到“值”,因为它不是“p-tree”的已知属性

[英]PrimeNG p-tree error: Can't bind to 'value' since it isn't a known property of 'p-tree'

我在我的 Angular2 webapp 中使用 PrimeNG,我想使用 p-tree 组件。 我在 app.module 中导入了 TreeModule:

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

确保在您的组件中导入Tree 例子:

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

解决了

我解决了在正确的文件中移动导入的问题。 我的应用程序有一个用于导入模块的自定义文件,因此它需要将导入文件放在这里而不是放在 app.module 文件中。

更新

在Primeng和Angular的最新版本中,导入应该是这样的——

import {TreeModule} from 'primeng/tree';
import {TreeNode} from 'primeng/api';

有关详细信息,请参阅详细信息 -

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM