我被放在别人的代码上,有一个类用作其他组件的基础。当我尝试 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/