如果我包含两个模块,它们都使用相同的选择器定义组件或指令(可以说a[routerLink]
).
ModuleA 使用选择器定义指令a[routerLink]
ModuleB 使用选择器定义指令a[routerLink]
AppModule 包括模块和用途<a routerLink="..."></a>
在其模板中。
那么使用哪个指令呢? Angular 如何解析在运行时选择哪个组件/指令?该行为是否记录在某处?
您应该收到此错误消息
More than one component matched on this element.
Make sure that only one component's selector can match a given element.
Conflicting components: ${componentTypeNames.join(',')}
from https://github.com/angular/angular/blob/c8a1a14b87e5907458e8e87021e47f9796cb3257/packages/compiler/src/template_parser/template_parser.ts#L663-L665 https://github.com/angular/angular/blob/c8a1a14b87e5907458e8e87021e47f9796cb3257/packages/compiler/src/template_parser/template_parser.ts#L663-L665
您需要确保声明或导入到单个 NgModule 中的组件不会发生冲突。
如果冲突的组件未在同一模块中导入或声明,则不会发生冲突。
也可以看看https://github.com/angular/angular/issues/10552#issuecomment-242998180 https://github.com/angular/angular/issues/10552#issuecomment-242998180
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)