[英]Angular APP_INITIALIZER with Http Request
I'm trying to incorporate APP_INITIALIZER in my angular project to make a http request to get a list of user permissions for display. 我试图将APP_INITIALIZER合并到我的角度项目中,以发出http请求以获取显示用户权限的列表。 However the http request inside the function its calling doesn't appear to be firing.
但是,函数调用中的http请求似乎没有触发。
providers: [
PermissionService,
{ provide: APP_INITIALIZER, useFactory: (permissionServiceFactory: PermissionService) => () => permissionServiceFactory.getPermissions(), deps: [PermissionService], multi: true },
],
getPermissions() {
return this.http.get(this.url).pipe(
map(this.extractPermissions),
catchError(this.handleError)
)
}
I can see getPermissions being called and I've tried putting it inside a setTimeout but nothing seems to be working. 我可以看到调用了getPermissions,并且尝试将其放入setTimeout中,但似乎没有任何效果。 Is this a issue with APP_INITIALIZER?
这是APP_INITIALIZER的问题吗? It seems rather simple I don't know what I would be doing wrong.
似乎很简单,我不知道我会做错什么。
getPermissions() needs to return a promise getPermissions()需要返回承诺
getPermissions(): Promise<any> {
const temp = return this.http.get(this.url).pipe(
map(this.extractPermissions),
catchError(this.handleError)
);
return temp;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.