我有我需要在整個應用程序中使用一些自定義的指令,在全球範圍內註冊一個指令。如何註冊我的指令以在整個應用程序中使用?我遇到的其他問題都過時了。我需要角2最終版本的解決方案2.1.0在angular2最終
我main.ts
看起來像這樣
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { AppModule } from './app.module';
//enableProdMode(); //Uncomment for production
platformBrowserDynamic().bootstrapModule(AppModule)
.then((success: any) => console.log('App bootstrapped'))
.catch((err: any) => console.error(err));
我的應用程序有6個模塊使用延遲oading
appmodule
--contact module
--project module
--restmodules
...
當我註冊的產品指令模塊,它運行良好。所以,我在模塊的休息,我註冊了這個指令在appmodule.ts
這樣
import { mdinput} from './shared/mdinput.directive';
@NgModule({
imports: [
AppRoutingModule
],
declarations: [
AppComponent,mdinput
],
providers: [DataService],
bootstrap: [AppComponent]
})
export class AppModule {
}
現在這個特定的指令無法正常工作使用此指令。它也沒有給出任何錯誤。
只需將它添加到您的NgModule的聲明。 https://angular.io/docs/ts/latest/guide/attribute-directives.html –
@JBNizet但它不工作的模塊不同勢 –
不要讓我們猜你想達到的目標。編輯您的問題,並張貼關於你的指令,你的模塊,等等。你可能需要將其添加到出口,太,但沒有看到任何東西的所有相關信息,這是很難猜測。 –