0
我正在創建服務,在不導入組件的情況下可以看到服務。Angular 2中的全局可見服務問題
我的自舉功能:
export function main(initialHmrState?: any): Promise<any> {
console.log(APP_PROVIDERS);
return bootstrap(App, [
...PLATFORM_PROVIDERS,
...ENV_PROVIDERS,
...APP_PROVIDERS
])
.then(decorateComponentRef)
.catch(err => console.error(err));
}
應用提供商定義:
export * from './app.component';
export * from './user.state';
export * from './app.service';
import { UserState } from './user.state';
import { AppState } from './app.service';
// Application wide providers
export const APP_PROVIDERS = [
UserState,
AppState
];
,我不能把它的部件構造
constructor(private userState: UserState) {}
我怎樣才能解決我的問題?
我在控制檯時有錯誤我在組件中使用它: /home/maksym/untill/trunk/unTill.Modern/Code/App/src/app/backoffice/backoffice.component.ts:13:53 找不到名稱'UserState'。 –
對不起,我在錯誤的地方用'any'取代了'UserState'。我更新了我的答案。你仍然需要在你提供它的地方輸入'UserState'。 –