我正在尝试从项目 A 中将feature module
导入项目 B 。
(在浏览器中运行项目 B 后的错误)
(compiler.js:2175)
Uncaught Error: The template specified for component CrudTableComponent is not a string
at syntaxError (compiler.js:2175)
at DirectiveNormalizer.normalizeTemplate (compiler.js:17649)
at CompileMetadataResolver.loadDirectiveMetadata (compiler.js:19820)
at compiler.js:25829
at Array.forEach (<anonymous>)
at compiler.js:25828
at Array.forEach (<anonymous>)
at JitCompiler._loadModules (compiler.js:25825)
at JitCompiler._compileModuleAndComponents (compiler.js:25805)
at JitCompiler.compileModuleAsync (compiler.js:25767)
我从另一个项目导入的原因是我希望计划从项目 A 生成一个库。
(项目 A 的功能模块)
@NgModule({
declarations: [
>>CrudTableComponent,
>>BulkCrudTableComponent,
],
imports: [
CommonModule,
ReactiveFormsModule,
MatTableModule,
...
MatCardModule,
],
exports: [
ReactiveFormsModule,
MatTableModule,
...
MatCardModule,
>>CrudTableComponent,
>>BulkCrudTableComponent,
]
})
export class CrudTableModule {}
(功能模块项目 B ,出现错误的项目,您看到我离开了我的项目(B)...)
import { CrudTableModule } from '../../../../../../privat/mat-crud-table/src/app/crudTableProject/crud-table.module';
...
@NgModule({
declarations: [
loads of declarations ...
],
entryComponents: [
some entry components ...
],
imports: [
some imports ...
CrudTableModule,
],
exports: [
bazillion exports ....
CrudTableModule,
],
})
export class MyCoreModule {}
可能与以下方面有关:
https://stackoverflow.com/a/57090749/6852937
当我“玩转”并将 A 中的templateUrl:
更改为template:
时
奇怪的事情正在发生:
compiler.js:2175 Uncaught Error: Template parse errors:
More than one component matched on this element.
Make sure that only one component's selector can match a given element.
Conflicting components: MatButton,MatButton ("
<mat-dialog-actions fxLayout="row nowrap" fxLayoutAlign="space-between center">
[ERROR ->]<button mat-stroked-button color="primary" (click)="logout()">Ausloggen</button>
<button "): ng:///MayaCoreModule/LogoutModalComponent.html@12:12
More than one component matched on this element.
Make sure that only one component's selector can match a given element.
Conflicting components: MatButton,MatButton (" <button mat-stroked-button color="primary" (click)="logout()">Ausloggen</button>
[ERROR ->]<button mat-stroked-button (click)="close()">Abbrechen</button>
我玩得更多,而且我知道删除材料进口以摆脱材料牛市错误。
答案 0 :(得分:1)
我确实有同样的问题。当我们确实从外部项目根目录处理组件时会出现这种情况。
此行中的错误:https://github.com/angular/angular/blob/master/packages/compiler/src/directive_normalizer.ts#L73
在此行中, prenormData。 template 的值是一个Object而不是字符串,这将引发异常。要解决此问题,您需要检查prenormData.template是否是一个对象并获取默认属性的值。像这样:
if (typeof prenormData.template !== 'string' && ('default' in prenormData.template)) {
prenormData.template = prenormData.template.default;
}
if (typeof prenormData.template !== 'string') {
throw syntaxError("The template specified for component " + stringify(prenormData.componentType) + " is not a string");
}
但是,为此,我们必须为Angular打开PR,然后等待他们批准:(