【问题标题】:ERROR in : Can't resolve all parameters for Service when build with ng build --prod错误:使用 ng build --prod 构建时无法解析服务的所有参数
【发布时间】: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


【解决方案1】:

我发现了问题!

您将 DataService 标记为 @Injectable,但构造函数有一个不可注入的参数(url:字符串)。

您必须从提供者列表中删除 DataService 并删除 @Injectable 标签

【讨论】:

  • 你能说得更具体些吗
猜你喜欢
  • 2018-12-18
  • 2018-04-15
  • 2018-03-21
  • 2020-04-29
  • 2022-09-27
  • 2022-09-25
  • 2019-11-06
  • 2019-11-29
  • 2020-03-14
相关资源
最近更新 更多