gpt4 book ai didi

javascript - 当将服务注入(inject)(导入)到我的构造函数中时,出现 "No provider"错误

转载 作者:行者123 更新时间:2023-12-03 08:23:13 24 4
gpt4 key购买 nike

Angular 2 - 当将服务注入(inject)(导入)到我的构造函数中时,我收到“无提供程序”错误。

这是我要导入的服务:

 export class EnvironmentService {

public baseurl: string = "/baseurl/example/";

}

这是我的类(class),出现错误:

import {Http, Headers} from "angular2/http";
import {Injectable} from 'angular2/angular2';
import {EnvironmentService} from './environmentService';

@Injectable()

export class AuthService {

constructor(private _environmentService: EnvironmentService) {

//This is where the error is.
console.log(this._environmentService);

}

isUserLoggedIn = (): Promise<boolean> => {

return new Promise((resolve, reject) => {
resolve(true);
})
}

}

最佳答案

app.module.ts中添加AuthServiceProviders

关于javascript - 当将服务注入(inject)(导入)到我的构造函数中时,出现 "No provider"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33656298/

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