angular - 无法解析...的所有参数([object Object],[object Object],?,?)

标签 angular

我被放在别人的代码上,有一个类用作其他组件的基础。当我尝试 ng serve --aot(或 build --prod)时,我得到以下信息。

    @Component({
      ...,
      providers: [NgProgress]
    })
    export class ReferentielComponent {
        vars...

      constructor(referentielService: ReferentielService, ngProgressService: NgProgress, referentielName: string, referentielViewName: string) {
        this.ngProgressService = ngProgressService;
        this.referentielName = referentielName;
        this.referentielViewName = referentielViewName;
        this.referentielService = referentielService;
      }
    }

扩展之一

    @Component({
      ...,
      providers: [ReferentielService, NgProgress ]
    })
    export class ProgrammeComponent extends ReferentielComponent {
      constructor(referentielService: ReferentielService, ngProgressService: NgProgress ) {
        super(referentielService, ngProgressService, "programme", "programme");
      }
    }

引用服务

@Injectable()
export class ReferentielService {

  private referentielUrl = environment.restApiUrl + '/referentiel';
  constructor(private _http: HttpClient) { }

  getReferentiels(tableName: string) {
    return this._http.get<Referentiel[]>(this.referentielUrl + '/' + tableName);
  }
}

我明白了

Failed to compile.

Can't resolve all parameters for ReferentielComponent in /src/app/components/referentiel/referentiel.component.ts: ([object Object], [object Object], ?, ?).

我尝试过设置默认值,但无法理解或使用我在 SO 上看到的其他案例。

我正在研究 Angular 4。

最佳答案

编译器不明白这个字符串是什么,因为他在编译时没有办法分辨。所以你必须使用 @Inject() 手动告诉他

在这种情况下,我的构造函数将如下所示:

constructor(referentielService: ReferentielService, ngProgressService: NgProgress, @Inject("") referentielName: string, @Inject("") referentielViewName: string) {

我个人不需要注入(inject)空字符串以外的任何东西,至少现在是这样。

关于angular - 无法解析...的所有参数([object Object],[object Object],?,?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55690785/

相关文章:

javascript - 在 JavaScript 中使用 Angular 变量

angular - 如何使用我的 http 请求配置代理?

Angular 5 动态地将组件插入现有标记?

node.js - 具有持久数据的NodeJS + RxDB + Electron

angular - Validators.nullValidator(control : AbstractControl)?) 有什么意义

javascript - 测试组件时覆盖管道

c# - Angular 应用程序无法在 dotnet core/IIS 下启动

angular - 在生产中更改或换出 Service Workers 的正确步骤是什么?

带有 Tabulator 按钮的 Angular Material Tab 焦点

angular - 当我有不同的 baseUrl 和 apiUrl 时,为不同的环境设置 cypress