gpt4 book ai didi

angular - `this.appInits[i] is not a function` 错误发生在 `APP_INITIALIZER`

转载 作者:行者123 更新时间:2023-12-04 14:34:15 24 4
gpt4 key购买 nike

我正在尝试一个简单的 APP_INITIALIZER使用我的 angular 应用程序,但出现错误
this.appInits[i] is not a function - 无法弄清楚问题。

这是我的应用程序模块:

import { NgModule, APP_INITIALIZER  } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule, HttpClient, HTTP_INTERCEPTORS } from '@angular/common/http';


export function onAppInit1(){
return new Promise((resolve,reject) => {
return setTimeout(() => resolve(true), 5000);
})
}

@NgModule({
declarations: [
AppComponent,
SignInComponent
],
imports: [

],
providers: [
{
provide:APP_INITIALIZER,
useFactory:onAppInit1,//getting error
multi: true
},
{
provide: HTTP_INTERCEPTORS,
useClass: InsertAuthTokenInterceptor,
multi: true
}
],

bootstrap: [AppComponent]
})
export class AppModule { }

最佳答案

onAppInit1 应该返回一个返回 promise 的函数

export function onAppInit1(){
return () => {
return new Promise((resolve,reject) => {
return setTimeout(() => resolve(true), 5000);
})
}
}

关于angular - `this.appInits[i] is not a function` 错误发生在 `APP_INITIALIZER`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56165277/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com