根据下拉文本框中的选择值,将在angular中被启用或禁用



我写的代码根据我的一个下拉菜单,包括2个值,即启用,禁用。根据选择,应该启用和禁用文本框。有谁能告诉我怎么

import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-dropdown',
templateUrl: './dropdown.component.html',
styleUrls: ['./dropdown.component.css']
})
export class DropdownComponent implements OnInit {
des = false
constructor() { }

onchange(){
if (true) {
this.des=false

}
else{
this.des= true
}
}
ngOnInit(): void {
}
}
<select name="dropdown" id="this">select the correct value 
(change)="onchange()"
<option value="yes">yes</option>
<option value="No">No</option>
</select>
<input type="text" [disabled]="!des">

取选项的值以及我可以在if-else部分给出的条件

在HTML文件中添加event作为参数

<select name="dropdown" (change)="onChange($event)">
select the correct value
<option value="No">No</option>
<option value="yes">yes</option>
</select>
<input type="text" [disabled]="des">

和在ts文件中添加函数

onChange(ev) {
this.des = ev.target.value === 'yes'
}

相关内容

最新更新