我有json:
public example=[{
array:[item1, item2,]
},
{
array:[item1, item2,]
}]
檔案html:
<div *ngFor="let item of example">
<div *ngIf="check(item.array)"> ...</div>
</div>
但是在 ngOnInit() 中呼叫函式檢查,它會出錯
check(...request: string[]){
return this._RolesService.checkRoles(request);
}
ngOnInit(): void {
let req:string[] = ['string1'];
if(this.check(req)){}
}
性別 html 沒問題,所以當我在 ngOnInit 中呼叫函式 check() 時,它出現錯誤:“字串 []”型別的引數不可分配給“字串”型別的引數。
uj5u.com熱心網友回復:
您應該將代碼更改為:
let req:string[] = ['string1'];
if(this.check(...req)){}
或者
let req = 'string1';
if(this.check(req)){}
uj5u.com熱心網友回復:
你能分享一下代碼this._RolesService.checkRoles(request)嗎?我認為這個函式接受一個string作為引數,但你傳遞['string1']的是一個字串陣列。這就是引發錯誤的原因。
根據您提供的當前資訊,我認為這是問題所在。
更正的解決方案: 感謝此解決方案下的評論,解決您的問題的方法之一是在呼叫方法時使用擴展運算子:
this.check(...req)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/484024.html
標籤:有角度的 打字稿 angular2-模板
上一篇:如何將角度的布林值系結到api?
