【发布时间】:2021-10-26 10:55:14
【问题描述】:
我正在尝试禁用基于方法的选项。
例如我有 4 个选项:
A
B
C
D
我的方法(示例):
if(name == A) {
disable select for A.
}
我的代码:
this.http.getDataFromServer("api/....).subscribe((resp) => {
this.code = resp.data["route"];
console.log(this.code);
});
在this.code 我有多个数据。这是组件中的 HTML:
<div class="form-group">
<label for="route_code">
Route Code
</label>
<select type="text" class="form-control" formControlName="route_code" (change)="codeSelected($event.target.value)">
<option [value]="r.id" *ngFor="let r of code" [disabled]="disable()">
{{r.code}}
</option>
</select>
</div>
这里有我的 HTML 代码,其中r.code 是选项。
搜索后我找到了[disable],我可以将它分配给一个方法disable()
Component.ts 有这个代码:
disable(){
}
我应该在 disable 方法中添加什么?例如,如果 r.code == "A",我想禁用一个选项。你能帮帮我吗?
【问题讨论】:
标签: javascript angular html-select