1
在这里我创建两个ts文件一个是服务另一个是一般服务我实现了一些服务和调用一般ts文件,而我的页面获取加载其通过错误为在NoProviderError.BaseError [作为构造]错误:无法解析CustomerService的所有参数:(?)
Service.ts
@Component({
templateUrl: "../../template/customer/customer.html",
providers: [CustomerService]
})
Url = "http://localhost:54873/Api/Home/GetEmp"
public constructor(private _http: Http) {
}
getEmpData() {
debugger;
return this._http.get(this.Url).map(this.extractData).catch(this.handleError);
}
Component.ts
@Component({
templateUrl: "../../template/customer/customer.html",
providers: [CustomerService]
})
@Injectable()
export class CustomerComponent {
Url = "http://localhost:54873/Api/Home/GetEmp"
getfun: string;
constructor(private _HttpService: CustomerService) { }
getData() {
return this._HttpService.getEmpData().subscribe(data => this.getfun = JSON.stringify(data), error => alert('This is error...'),
() => console.log());
}
这是哪里的服务?您只发布了该课程的一部分。你有没有在'providers'中指定它?这个问题缺乏http://stackoverflow.com/help/mcve – estus
@estus我将编辑我的代码,我指定在提供商bt其通过一个错误 –
请验证我编辑的代码 –