Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在angular中验证mat选择列表?_Angular_Angular Material - Fatal编程技术网

如何在angular中验证mat选择列表?

如何在angular中验证mat选择列表?,angular,angular-material,Angular,Angular Material,我已经编写了一个代码来显示产品列表,它有选择产品的功能(使用复选框)。当我保存它时,我需要知道他们选择了哪些产品。请帮忙 代码 从'@angular/core'导入{Component,OnInit,Inject}; 从“@angular/material”导入{MatDialogRef,MAT_DIALOG_DATA}; @组成部分({ 选择器:“应用程序工作单状态”, templateUrl:“工单状态.component.html”, STYLEURL:['work-order-statu

我已经编写了一个代码来显示产品列表,它有选择产品的功能(使用复选框)。当我保存它时,我需要知道他们选择了哪些产品。请帮忙

代码

从'@angular/core'导入{Component,OnInit,Inject};
从“@angular/material”导入{MatDialogRef,MAT_DIALOG_DATA};
@组成部分({
选择器:“应用程序工作单状态”,
templateUrl:“工单状态.component.html”,
STYLEURL:['work-order-status.component.scss']
})
导出类WorkOrderStatusComponent在NIT上实现{
状态列表:字符串[]=['InRepair'、'Hold'、'Closed'、'Build'、'Shipped'、'WIP'];
worderobj:任何;
构造函数(公共dialogRef:MatDialogRef,
@注入(MAT_对话框_数据)公共数据:任意){
this.worderobj=[data];
}
恩戈尼尼特(){
}
public onClose():void{
this.dialogRef.close();
}
公共onSave(){
}
}
工单状态.component.html

<mat-selection-list #status>
    <mat-list-option [value]="list" *ngFor="let list of statuslist">
        {{list}}
    </mat-list-option>
</mat-selection-list>

{{list}}
选择的选项:{{status.selectedOptions.selected.length}
改变

将第一位值输入属性绑定到mat list option组件并绑定列表值

component.html

<mat-selection-list #status>
    <mat-list-option [value]="list" *ngFor="let list of statuslist">
        {{list}}
    </mat-list-option>
</mat-selection-list>

onSave(status){
    const value = status.selectedOptions.selected.map(sel=>sel.value);
    console.log(value);
  }