Angular2-无法在其他组件中使用指令
我有一个具有以下应用程序模块的angular应用程序Angular2-无法在其他组件中使用指令,angular,angular2-routing,angular2-directives,Angular,Angular2 Routing,Angular2 Directives,我有一个具有以下应用程序模块的angular应用程序 import {BrowserModule} from '@angular/platform-browser'; import {NgModule} from '@angular/core'; import {LocationStrategy, HashLocationStrategy} from '@angular/common'; import {AppComponent} from './app.component'; // Im
import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {LocationStrategy, HashLocationStrategy} from '@angular/common';
import {AppComponent} from './app.component';
// Import components
import {
AppAsideComponent,
AppBreadcrumbsComponent,
AppFooterComponent,
AppHeaderComponent,
AppSidebarComponent,
AppSidebarFooterComponent,
AppSidebarFormComponent,
AppSidebarHeaderComponent,
AppSidebarMinimizerComponent,
APP_SIDEBAR_NAV
} from './components';
const APP_COMPONENTS = [
AppAsideComponent,
AppBreadcrumbsComponent,
AppFooterComponent,
AppHeaderComponent,
AppSidebarComponent,
AppSidebarFooterComponent,
AppSidebarFormComponent,
AppSidebarHeaderComponent,
AppSidebarMinimizerComponent,
APP_SIDEBAR_NAV
]
// Import directives
import {
AsideToggleDirective,
NAV_DROPDOWN_DIRECTIVES,
ReplaceDirective,
SIDEBAR_TOGGLE_DIRECTIVES
} from './directives';
const APP_DIRECTIVES = [
AsideToggleDirective,
NAV_DROPDOWN_DIRECTIVES,
ReplaceDirective,
SIDEBAR_TOGGLE_DIRECTIVES
]
import {AppRoutingModule} from './app.routing';
@NgModule({
imports: [
AppRoutingModule,
BrowserModule
],
declarations: [
AppComponent,
...APP_CONTAINERS,
...APP_COMPONENTS,
...APP_DIRECTIVES
],
exports: [],
providers: [{
provide: LocationStrategy,
useClass: HashLocationStrategy
}],
bootstrap: [AppComponent]
})
export class AppModule {
}
我想在另一个模块的组件中使用指令AsideToggleDirective
,该模块是主AppModule
的子模块。
我能够在const APP_components
中提到的组件中正确使用它,但它不适用于其他模块组件
我错过了什么
另外,其他模块由路由定义。只需将
AsideToggleDirective
添加到导出数组:)只需将AsideToggleDirective
添加到导出数组:)您应该创建将声明和导出AsideToggleDirective的模块。然后在AppModule中导入此模块,在另一个模块中请参见,您应该创建将声明和导出AsideToggleDirective的模块。然后在AppModule和另一个模块中导入此模块,请参见