【发布时间】:2023-04-09 19:27:01
【问题描述】:
数据服务
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);
}
}
我正在创建一个服务 DataService,它具有所有 http 方法(get、create、delete、update),并且项目中使用的所有服务都在扩展 DataService。在 DataService 的构造函数中,我传递了 http 对象和通过对父构造函数进行 super(url,http) 调用,从子类获取 url。这样,我在最新版本的 cli 中遇到错误,但在旧版本中没有。我正在 getting使用 ng build --prod 构建时出现此错误,并且 ng build 中出现 not getting 错误。谁能帮忙。
【问题讨论】:
-
在此处发布您的代码
-
代码已发布,您可以尽快提供帮助
-
也发布您的数据服务
-
@Sajeetharan ,请看code dataservice 代码已经存在
标签: angular service build angular-cli production-environment