我有 Angular 12 專案,它有 typescript 4.2.3 我收到一堆這些錯誤。在這種情況下,我將 appLang 引數傳遞給子組件。
所以這是我的html:
<app-bankcard-call-flows [appLang]="getLanguage()">
我正在嘗試從協調組件中提取價值:
public getLanguage() {
this.appLang = this.language;
}
我收到錯誤:
TS2322: Type 'void' is not assignable to type 'string'.
<app-bankcard-call-flows [appLang]="getLanguage()"></app-bankcard-call-flows>
uj5u.com熱心網友回復:
該方法getLanguage()不回傳任何內容,因此您實際上void是在[appLang]需要字串時傳遞給輸入。
使用[appLang]="appLang"或更改方法以回傳appLang:
public getLanguage(): string {
return this.language;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/409345.html
標籤:
