Angular 特定组件中的 2 个声明

Angular 2 declarations in specific component

上次我使用 Angular2 时,指令仍然存在,但现在 app.modules.ts 中有所谓的声明。问题是,如果我打算只在特定组件而不是主要组件中使用指令,我该怎么做?

customers.component.ts

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

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

export class CustomersComponent {
    customers = [
    { id: 1, name: 'Mix'},
    { id: 2, name: 'Ian'},
    { id: 3, name: 'Aniel'},
    { id: 4, name: 'Jess'},
    { id: 5, name: 'Jusi'},
    ];
}

customer.component.ts

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

@Component({
    selector: 'app-customer',
    templateUrl: 'app/customer/customer.component.html'
})

export class CustomerComponent {
    @Input() customer: {id: number, name: string};

    myColor = 'gray';
}

app.module.ts

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';

import { AppComponent }  from './app.component';
import { CustomerComponent } from './customer/customer.component';
import { CustomersComponent } from './customer/customers.component';

@NgModule({
  imports: [ BrowserModule, FormsModule ],
  declarations: [ AppComponent, CustomerComponent, CustomersComponent ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

我在想的是,当我将一个组件放在一个声明中时,每个组件都可以访问它,不像以前我只能在一个特定的声明中访问它。如果我在这里错了,请纠正我,如果在声明指令方面有更好的选择,请提出建议。

您可以将组件声明放入Feature Module
Feature Module 应导入应用程序模块。

现在由您决定是否认为您的组件是一个功能并且是否值得一个单独的模块。
我知道模块的所有这些事情并不像指令那样简单明了,但是 Angular2 中的一些设计问题无法通过其他方式解决。

文档:https://angular.io/guide/feature-modules