我被放在别人的代码上,并且有一个类用作其他组件的基础。当我尝试ng服务--aot(或构建--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上看到的其他情况。
我正在使用Angular4。
答案 0 :(得分:0)
编译器无法理解字符串是什么,因为他无法在编译时告诉字符串。因此,您必须使用@Inject()
手动告诉他在这种情况下,我的构造函数将如下所示:
constructor(referentielService: ReferentielService, ngProgressService: NgProgress, @Inject("") referentielName: string, @Inject("") referentielViewName: string) {
我个人至少现在不需要注入空字符串。