plx-districtTree是一个自定义组件,出现这个问题的原因基本就是模块加载的时候不能找到这个组件,说明没有正确引入这个组件,主要检测引入的问题!
注:按照通常引入做法,尽量引入Module,尽量避免直接引入component,以免漏掉某个组件的引入!
Uncaught Error: Template parse errors:
Can't bind to 'treeNodes' since it isn't a known property of 'plx-districtTree'.
1. If 'plx-districtTree' is an Angular component and it has 'treeNodes' input, then verify that it is part of this module.
2. If 'plx-districtTree' 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. ("
</div>
<div class="modal-body">
<plx-districtTree [ERROR ->][treeNodes]="treeNodes" (treeNodesChange)="treeNodesChange($event)"></plx-districtTree>
</div>
"): ng:///ProperyModule/PlxMELocationComponent.html@63:26
'plx-districtTree' is not a known element:
1. If 'plx-districtTree' is an Angular component, then verify that it is part of this module.
2. If 'plx-districtTree' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("
</div>
<div class="modal-body">
[ERROR ->]<plx-districtTree [treeNodes]="treeNodes" (treeNodesChange)="treeNodesChange($event)"></plx-districtT"): ng:///ProperyModule/PlxMELocationComponent.html@63:8
背景:本问题出现了2次,都是在引入组件的时候出现问题,再次记录。
组件结构是这样的
首先,在plx-meLocation中使用了districtTree的标签
<plx-districtTree [treeNodes]="treeNodes" [rootId]='rootId' (treeNodesChange)="treeNodesChange($event)"></plx-districtTree>
其次,引入方式是:在plx-meLocation.modlue中引入districtTree.module
import { DistrictTreeModule } from './districtTree/districtTree.module';
而整个组件是以plx-meLocation暴露给用户的,当用户使用该组件时,如果仅仅引进组件的形式,如下:
import { PlxMELocationComponent } from 'umebn-frontend-tools/plx-meLocation/plx-meLocation.component';
这样就会出现上述错误,以这种方式引入,解析组件模板时,自然找不到plx-districtTree,
正确方式要进入plx-meLocation.modlue:
import { PlxMELocationModule } from 'umebn-frontend-tools/plx-meLocation/plx-meLocation.module';
(当然这并不是绝对的,还要看组件是如何设计的,由于本组件plx-meLocation使用plx-districtTree时,是在plx-meLocation.modlue中引入districtTree.module,故用户使用时,引入plx-meLocation.modlue,才能保证编译时找到districtTree.module,进而找到plx-districtTree,否则编译时,编译器根本不认识plx-districtTree!)