我正在嘗試使用一些 Angular 材質組件,例如 mat-checkbox,但是當我設定自定義屬性時,我得到
無法讀取未定義的屬性(讀取“getAttribute”)
使用的代碼是這樣的:
<li *ngFor="let instancia of tipo_maquina.instancias">
<mat-checkbox
(change)="onCheckChange($event, $event.source, $event.checked)"
[attr.typeid]="instancia.id">
{{instancia.nombre}}
</mat-checkbox>
</li>
onCheckChange(event: any, checkbox: MatCheckbox, isChecked: boolean){
console.log("check event")
console.log(event.target.getAttribute('typeid'));
}
uj5u.com熱心網友回復:
的型別$event應該是MatCheckboxChange,它有 2 個屬性
/** Change event object emitted by MatCheckbox. */
export declare class MatCheckboxChange
{
/** The source MatCheckbox of the event. */
source: MatCheckbox;
/** The new `checked` value of the checkbox. */
checked: boolean;
}
所以 target 不存在MatCheckboxChange,你會得到一個錯誤
error TS2339: Property target' doesn't exist on type 'MatCheckboxChange'。
正如@MikeOne 建議的那樣,只需傳遞instancia.id給該onCheckChange($event, instancia.id)方法。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/476925.html
下一篇:如何使用位置居中塊?
