我有两个数组serviceOptions
和reactivePackages
。在每个服务选项的旁边有一组反应包(如下拉列表所示)。
现在我在循环中动态创建dropdowns。我的问题是如何在表单提交时获得所选的下拉列表选项?(这是表单的一部分)
<label *ngFor="let service of serviceOptions">
<b>{{service.serviceName}}</b>
<br /><br />
<md-select placeholder="Select Package" formControlName="packageName" size="30">
<ng-container *ngFor="let package of (reactivePackages | async)">
<md-option *ngIf="service.serviceId==package.serviceId" [value]="package" (click)="hello()">
{{ package.packageName }}
</md-option>
</ng-container>
</md-select>
<br /> <br />
</label>
发布于 2017-07-27 10:42:32
You can achieve it by saving the selected option in a variable.
You need to follow just two steps.
1. Create a method on component.ts that will store the selected option.
Example-
selectedData(event: any) {
this.storedData = event.target.value;
}
2. Call this method on html.
Example-
<select class="form-control" (change)="selectedData($event)">
<option *ngIf="service.serviceId==package.serviceId" [value]="package">{{ package.packageName }}</option>
</select>
3.Then simply call a method that will save the selected data.
https://stackoverflow.com/questions/45345342
复制