角度6:模板解析错误:“组件”不是已知元素

时间:2019-01-15 09:34:11

标签: angular angular6

我正在尝试在另一个组件中使用组件选择器,但是它显示错误。

Uncaught Error: Template parse errors:
'registryTable' is not a known element:
1. If 'registryTable' is an Angular component, then verify that it is part of this module.
2. To allow any element add 'NO_ERRORS_SCHEMA' to the '@NgModule.schemas' of this component. ("[ERROR ->]<registryTable></registryTable>"): 

我尝试将其添加到app.module.ts,但仍然会引发该错误。

这是我正在使用的代码的一部分。

app.module.ts

import { RegisteryComponent } from './registery/registery.component';
import { RegisteryTableComponent } from './registery/registry-table/registery-table.component';
@NgModule({
    declarations: [
        AppComponent,
        RegisteryComponent,
        RegisteryTableComponent
    ],
    imports: [
    ...
    ],
    exports: [
        CdkTableModule,
        CdkTreeModule
    ],
    providers: [...],

    entryComponents: [],
    bootstrap: [AppComponent]
})
export class AppModule { }

registry.component.ts

import { Component, OnInit, ViewChild } from '@angular/core';

import { RegisteryTableComponent } from './registry-table/registery-table.component';

@Component({
    selector: 'app-registery',
    template: '<registry-table></registry-table>',
    styleUrls: ['./registery.component.scss']
})
export class RegisteryComponent implements OnInit {
    @ViewChild(RegisteryTableComponent) registeryTable: RegisteryTableComponent;

    constructor() { }


    ngOnInit() { }
}

registry-table.component.ts

import { Component, OnInit, ViewChild, Input } from '@angular/core';

@Component({
    selector: 'registery-table',
    templateUrl: './registery-table.component.html',
    styleUrls: ['./registery-table.component.scss']
})
export class RegisteryTableComponent implements OnInit {

    constructor() { }

    ngOnInit() {}
}

我已经尝试过的:

  1. 将{{1}中的RegisteryTableComponent添加到entryComponents中。
  2. app.module.ts中的RegisteryTableComponent数组中添加了exports

我尝试了针对类似错误找到的大多数解决方案,但没有一个对我有用。 任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

好像您将选择器的错字由registery-table更改为registry-table

答案 1 :(得分:0)

更改registry-table.component.ts中的选择器 从“注册表”到“注册表”