3
我有两个模块:改变根模块之间共享数据
第一:
@NgModule({
imports: [
BrowserModule,
FormsModule,
SharedModule.forRoot()
],
declarations: [
FirstComponent
],
bootstrap: [ FirstComponent ]
})
export class AppModule { }
第二:
@NgModule({
imports: [
BrowserModule,
FormsModule,
SharedModule.forRoot()
],
declarations: [
ScndComponent
],
bootstrap: [ ScndComponent ]
})
export class AppModule { }
,并用静态.forRoot()共享模块
@NgModule({})
export class SharedModule {
static forRoot() {
return {
ngModule : SharedModule,
providers : [DumyService]
}
}
}
我的DumyServise有一些道具'p aramd”,我想通过模块观看变化
@Injectable()
export class DumyService {
paramd : string;
}
模块(第一和第二)的两个组成部分我有构造
private ds: DumyService
。
然后,让我们说我有一些的onclick方法在第一模块组件的某些成分,改变
clickToChangeParam() {
this.ds.paramd = 'new value';
}
而且我希望有这改变了这两个模块。 我该如何处理?
为什么你想要2个根模块? –
因为我需要在应用程序的不同dom部分中使用单独的模块。 我知道,我怎样才能运行它没有一些组件指令 –
WebArtisan
在angular1中更容易有标记的根组件。在A2中我看不到这种可能性。 A2只能通过自定义指令运行。我错了吗? – WebArtisan