我需要从Angular初始级别的服务中加载配置。因此,对于演示,我创建了boot module,boot class并将Angular核心的APP_INITIALIZER加载到启动模块中。
检查以下文件,我看不到console.log(“ Init Function works”))以及console.log(“ GET CONFIG WORKS”]]]]
如果有任何问题,请纠正我。
//模块文件boot.modue.ts
import { APP_INITIALIZER, NgModule } from '@angular/core'; import { CommonModule } from '@angular/common'; import { Boot, Config, Menu } from './../../core/classes'; import { MenusService } from './../services/'; export function init(_boot: Boot) { console.log("Init Function works"); return () => { return _boot.getConfig(); }; } @NgModule({ imports: [ CommonModule ], declarations: [], providers: [Boot, { provide: APP_INITIALIZER, useFactory: init, deps: [Boot], multi: true }] }) export class BootModule { constructor() { } }
//类文件boot.ts
import 'rxjs/add/operator/toPromise';
export class Boot {
/**
* getConfig
*/
public getConfig(): Promise<any> {
console.log("getConfig");
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log("GET CONFIG WORKS");
resolve();
}, 3000);
});
}
/**
* initMenus
*/
public initMenus() {
}
}
我需要从Angular初始级别的服务中加载配置。因此,在演示中,我创建了启动模块,启动类,并将Angular核心中的APP_INITIALIZER加载到启动模块中。检查...
它们的问题是您的init_app函数,它应该返回Promise,但是您用花括号将其弄乱了,然后返回void。