Select
在角度9中已禁用。
请记住,boolean
在此示例中禁用了使用值的操作,如果未选择国家/地区,则我将(change)
事件与select
选项一起使用。
find.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>