可以将“客户列表”添加到“客户”模块

时间:2019-09-27 13:45:54

标签: angular typescript

我是Angular的新手,并且在尝试将''添加到我的customer.component.html中时出现以下错误:

  
      
  1. 如果“ app-customers-list”是Angular组件,请验证它是否属于此模块。
  2.   
  3. 如果“ app-customers-list”是Web组件,则将“ CUSTOM_ELEMENTS_SCHEMA”添加到该组件的“ @ NgModule.schemas”   [...]
  4.   

我现在这是一个非常常见的错误,但是我似乎找不到我所缺少的东西。看来我没有正确地将我的客户列表组件导入到customers.module。

这是我的文件:

  • customers.module.ts:

    import { NgModule }      from '@angular/core';
    import { CommonModule } from '@angular/common';
    
    import { CustomersComponent }  from './customers.component';
    import { CustomersListComponent } from './customers-list/customers-list.component';
    
    @NgModule({
    imports:      [ CommonModule ],
    declarations: [ CustomersComponent, CustomersListComponent ],
    exports: [ CustomersComponent,CustomersListComponent ]
    
     })
     export class CustomersModule { }
    
  • customer.list.component.ts:

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

@Component({
  selector: 'app-customers-list',
  templateUrl: './customers-list.component.html'

})
export class CustomersListComponent implements OnInit {

  constructor() { }

  ngOnInit() {
  }

}

1 个答案:

答案 0 :(得分:0)

您应该将组件导入app.module.ts中,而不要导入customers.module.ts中。

app.module.ts

// MODULES

import { BrowserModule } from '@angular/platform-browser';
import { ngModule } from '@angular/core';
...

// COMPONENTS

import { AppComponent } from './app.component';
import { CustomersComponent }  from './customers/customers.component';
import { CustomersListComponent } from './customers/customers-list/customers-list.component';
...

@NgModule({
  declarations: [
    AppComponent,
    ...
    CustomersComponent,
    CustomersListComponent
    ...
  ]
})