有可能產生具有角CLI服務並在app.module.ts在單個步驟中其添加爲提供商或使用特殊選項在ng g服務命令?角CLI生成服務和包括在一個步驟中提供
當執行:
$ ng g service services/backendApi
installing service
create src/app/services/backend-api.service.spec.ts
create src/app/services/backend-api.service.ts
WARNING Service is generated but not provided, it must be provided to be used
在它旁邊,(並且根據警告消息)我通常使用它添加到提供商部上app.module.ts文本編輯器:
@NgModule({
declarations: [
AppComponent,
...
],
imports: [
....
],
providers: [BackendApiService],
bootstrap: [AppComponent]
})
可以這樣做一個步驟,自動化這?
有沒有辦法在多個地方提供它呢? – Spurious
通常,在多個模塊中提供服務是不好的做法。也就是說,CLI不支持'--module'標誌。但是,您可以自己做,但我建議您在應用程序的更高級別提供它。 – delasteve