【发布时间】:2018-05-18 06:40:14
【问题描述】:
我在 angular4 中编写了我的代码,我想隐藏或禁用出现在下拉列表中的重复选项。你能告诉我隐藏它的可能方法吗?
我尝试从 -
实现代码How to Remove duplicate dropdown option elements with same value
assign.component.ts
import * as $ from 'jquery';
import { JQuery } from 'jquery';
export class AssignComponent implements OnInit {
seen = {};
getRolesList() {
var url = config.url;
var port = config.port;
this.http.post("http:....
.map(result => this.rolesList = result.json())
.subscribe((res: Response) => {
JQuery('.updateMappingUserRole').children().each(function() {
var txt = JQuery(this).attr('value');
if (this.seen[txt]) {
JQuery(this).remove();
} else {
this.seen[txt] = true;
}
});
}
assign.component.ts
<div class="col-md-6">
<div class="form-group">
<label for="role"> Role: </label>
<select class="form-control" name="updateMappingUserRole"
[formControl]=
"updateMappingRoleForm.controls['updateMappingUserRole']"
[(ngModel)]="updateMappingUserRole"
(change)="getRoleID(updateMappingUserRole)" id="role">
<option > {{updateMappingUserRole}}</option>
<option *ngFor="let i of rolesList">{{i.ROLE_CD}}
</option>
</select>
</div>
</div>
</div>
【问题讨论】:
标签: angular html-select dropdown