使用 Angular Material 5.2.4(客户端的选择列表组件)从客户端向服务器发送数据时出现问题。事实上,一个带有名称和 id 的复选框列表。因此,我无法将检查的 id 值数组发送到服务器,因为 浏览器仅对检查 MatListOption 做出反应,而由 id 组成的值本身,我无法从中获取。
这是component.html程序代码
<mat-selection-list
(selectionChange)="onSelection($event.source.selectedOptions.selected)" >
<mat-list-option *ngFor="let car of cars" [value]="car.id"
checkboxPosition="before" >
{{car.description}}
</mat-list-option>
</mat-selection-list>
组件.ts
import { Component, OnInit } from '@angular/core';
import { ListService } from '../list.service';
@Component({
selector: 'app-list-measu',
templateUrl: './list-measu.component.html',
styleUrls: ['./list-measu.component.css']
})
export class ListMeasuComponent implements OnInit {
cars: Array<any>;
current_selected: string;
id: Array<any> = new Array<any>();
constructor(private listService: ListService) { }
ngOnInit() {
this.listService.getAllmeasures().subscribe(data => {
this.cars = data;
});
}
onSelection(e){
console.log(e);
});
谢谢您的帮助!)