單體設計模式 in ionic 2. 任何人都可以告訴我如何在離子模式下製作單體設計模式。離子中的單體設計模式
export class example{
private constructor(){
}
}
請幫我沒怎麼使離子
單體設計模式 in ionic 2. 任何人都可以告訴我如何在離子模式下製作單體設計模式。離子中的單體設計模式
export class example{
private constructor(){
}
}
請幫我沒怎麼使離子
單例類只是將它作爲服務於AppModule
@Injectable()
export class Example {
constructor(){}
}
@NgModule({
declarations: [
MyApp,
HomePage,
DetailsPage
],
imports: [
IonicModule.forRoot(MyApp)
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
DetailsPage
],
providers: [
Example, // <<<=== your class
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
和角度DI會照顧那無處不在注入同一個實例。
這與sigleton設計模式相同 –
不,但不應該需要單獨設計模式。如果你想真正瞭解singelton設計模式,你應該從你的問題中刪除angular2和ionic標籤,並添加'typescript'和'design-patterns',單身與Angular或Ionic無關。 –
我應該在哪裏申報我的項目中的示例類 –
離子1或離子2? –
離子2請幫助相同 –
你的意思是提供者嗎? –