【发布时间】:2020-08-24 02:10:39
【问题描述】:
在我的角度应用程序中,我正在尝试执行一些条件代码,当结果为真时,我想禁用包含动态对象列表的选择选项,当尝试获取此选择的 id 时,它返回 null !!
ngOnInit() {
this.setScripts()
this.http.get('api/cities').subscribe((cities: any[]) => {
this.cities = cities;
})
this.http.get('api/user').subscribe(user => {
this.currentUser = user
localStorage.removeItem('currentUser')
localStorage.setItem('currentUser', JSON.stringify(this.currentUser))
this.user.patchValue({
firstName: this.currentUser.firstName,
lastName: this.currentUser.lastName,
email: this.currentUser.email,
profession: this.currentUser.profession,
gender: this.currentUser.gender,
birthDate: this.currentUser.birthDate,
phone: this.currentUser.phone,
oldPassword: this.currentUser.oldPassword,
password: this.currentUser.newPassword,
address: this.currentUser.address,
postalCode: this.currentUser.postalCode,
city: this.currentUser.city._id
})
})
this.returnUrl = this.route.snapshot.queryParams['returnUrl'] || '/';
if (this.compareDatesByDays(new Date().toISOString(), JSON.parse(localStorage.currentUser).municipalityDateChange) < 10) {
this.hideSelectMunicipality()
}
}
hideSelectMunicipality(){
$('#selectCity').prop('disabled', true);
}
***html
<div class="col-lg-7">
<select id="selectCity" name="city" class="custom-select form-control rounded" formControlName="city">
<option *ngFor="let city of cities" [value]="city._id" >{{city.name}}</option>
</select>
</div>
【问题讨论】:
-
您尝试将
[disabled]="condition"添加到您的<select>吗?
标签: javascript html jquery angular select