![](/img/trans.png)
[英]Angular - Can't resolve ALL Parameters for component ng build --prod
[英]ERROR in : Can't resolve all parameters for Service when build with ng build --prod
数据服务
import { Injectable } from '@angular/core';
import { Http, RequestOptions, Headers } from "@angular/http";
import { environment } from "../../environments/environment";
import 'rxjs/add/operator/map';
@Injectable()
export class DataService {
public options: RequestOptions;
constructor(protected url: string, protected http: Http) {
}
getAll() {
return this.http.get(this.url, this.options)
.map(
response => response.json()
)
}
get(id: string) {
return this.http.get(this.url + '/' + id, this.options)
.map(response => {
return response;
})
}
create(resource) {
return this.http.post(this.url, resource, this.options)
.map(response => {
return response;
})
}
update(resource) {
return this.http.put(this.url, resource);
}
delete(id: string) {
return this.http.delete(this.url + '/' + id)
}
}
儿童服务
import { Injectable } from '@angular/core';
import { DataService } from "../data.service";
import { Http, RequestOptions } from "@angular/http";
import { environment } from "../../../environments/environment";
@Injectable()
export class ChildService extends DataService{
constructor(http:Http) {
super(environment.url,http);
}
}
我正在创建一个具有所有http方法(get,create,delete,update)的服务DataService,并且该项目中使用的所有服务都在扩展DataService。在DataService的构造函数中,我从http传递了http对象和url通过使超(网址,HTTP)调用父constuctor.In这样,我得到一个错误的CLI的最新版本,但不是在旧的versions.I子类正与NG构建--prod建设时得到这个错误并没有在ng build中出错。任何人都可以帮忙。
我发现了问题!
您将DataService标记为@Injectable,但构造函数具有一个不可注入的参数(URL:字符串)。
您必须从提供者列表中删除DataService并删除@Injectable标签
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.