Directive
をComponent
にインポートできますか?私はngModule.declarations
にインポートしないようにしたい。コンポーネントを角型でインポートする
私はCustomDirective for Telerik Angular Gridに従っています。カスタムディレクティブでグリッドを設定することをお勧めしますが、このディレクティブは1つのコンポーネントにのみ必要です。名前の衝突を避けるため、ngModuleでのインポートは避けたいと考えています。
編集:
私はviewProviders
と試みたが、それは動作しません。 Hereは(ngModuleにインポートディレクティブを)作品plunkrです:
@NgModule({
imports: [ BrowserModule ],
declarations: [
AppComponent,
HighlightDirective
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
とhereは動作しませんplunkrです。 (コンポーネントにインポートディレクティブ):
@NgModule({
imports: [ BrowserModule ],
declarations: [
AppComponent,
],
bootstrap: [ AppComponent ]
})
export class AppModule { }
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html',
viewProviders: [HighlightDirective]
})
export class AppComponent {
color: string;
}
名前衝突を避けたい場合は、専用の '@ NgModule'を作成してください。https://angular.io/guide/ngmodule#feature-modules'矛盾するディレクティブがあります.' – yurzui
また、NgModuleにインポートする際にはポイントがありません1つまたは2つのコンポーネントが必要になります。 – Makla
@Fredrik Lundinがここに正解を書いた – yurzui