我被放在别人的代码上,有一个类被用作其他组件的基础。当我尝试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");
}
}ReferentielService
@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。
发布于 2019-04-16 15:25:03
编译器无法理解字符串是什么,因为他无法在编译时辨别。因此,您必须使用@Inject()手动告诉他
在这种情况下,我的构造函数将如下所示:
constructor(referentielService: ReferentielService, ngProgressService: NgProgress, @Inject("") referentielName: string, @Inject("") referentielViewName: string) {我个人不需要注入空字符串以外的任何东西,至少现在是这样。
https://stackoverflow.com/questions/55690785
复制相似问题