我有我需要在整个应用程序中使用一些自定义的指令,在全球范围内注册一个指令。如何注册我的指令以在整个应用程序中使用?我遇到的其他问题都过时了。我需要角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但它不工作的模块不同势 –
不要让我们猜你想达到的目标。编辑您的问题,并张贴关于你的指令,你的模块,等等。你可能需要将其添加到出口,太,但没有看到任何东西的所有相关信息,这是很难猜测。 –