Select
在 Angular 9 中禁用。
在此示例中,请记住禁用值的工作,如果未选择国家/地区boolean
,我将使用(change)
带有选项的事件。区域将被禁用。select
查找.component.ts 文件
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-find',
templateUrl: './find.component.html',
styleUrls: ['./find.component.css']
})
export class FindComponent implements OnInit {
isCountrySelected:boolean;
constructor() { }
//onchange event disabled false
onChangeCountry(id:number){
this.isCountrySelected = false;
}
ngOnInit(): void {
//initially disabled true
this.isCountrySelected = true;
}
}
find.component.html
//Country select option
<select class="form-control" (change)="onChangeCountry()" value="Choose Country">
<option value="">Choose a Country</option>
<option value="US">United States</option>
</select>
//region disabled till country is not selected
<select class="form-control" [disabled]="isCountrySelected">
<option value="">Choose a Region</option>
<option value="">Any regions.</option>
</select>