How can I display a select list within an Angular Material table?
error:
TS2339: Property 'element' does not exist on type 'MyaccountComponent'.
<mat-option *ngFor="let role of element.validRoles" [value]="role.value">
I get the same error if I change element.validRoles
to validRoles
too.
Component:
export class MyaccountComponent implements OnInit {
displayedColumns: string[] = ['email', 'role', 'rolestatus', 'validRoles'];
dataSource = [];
ngOnInit(){
this.getAllUsers();
}
constructor(private userService: UserService) { }
getAllUsers(){
const obs = this.userService.getAllRegisteredUsers();
obs.subscribe(data => {
console.log(data.users);
this.dataSource = data.users
});
}
}
Template:
<ng-container matColumnDef="validRoles">
<th mat-header-cell *matHeaderCellDef> Assign Role</th>
<mat-form-field appearance="fill">
<mat-label>Roles</mat-label>
<mat-select>
<mat-option *ngFor="let role of element.validRoles" [value]="role.value">
{{role.viewvalue}}
</mat-option>
</mat-select>
</mat-form-field>
</ng-container>
My data is in the format:
data.users.validRoles = [
{value: "admin", viewvalue: "Admin"}
];