Estoy tratando de usar algunos componentes de material angular, como mat-checkbox, pero cuando configuro un atributo personalizado, obtengo
No se pueden leer las propiedades de undefined (leyendo 'getAttribute')
El código utilizado es como va:
<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')); }El tipo de $event debe ser MatCheckboxChange y tiene 2 propiedades
/** 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; } Por lo tanto, el destino no existe en MatCheckboxChange y obtendrá un error de error TS2339: Property target' does not exist on type 'MatCheckboxChange' .
Como sugirió @MikeOne, simplemente pase instancia.id al onCheckChange($event, instancia.id) .