[英]static angular select option
<input [formControl]="twitterHandle" id="twitterHandle" placeholder="twitterHandle">
in there i get input via that and using following code get the input value 在那儿我通过它得到输入,并使用以下代码获得输入值
twitterHandle=new FormControl();
twitterHandle:this.twitterHandle.value,
simillar way i need to add static select input to form how to do that and how to edit following 类似的方式,我需要添加静态选择输入以形成操作方法以及如何编辑以下内容
<select>
<option value="option">country1</option>
<option value="option1">Sri lanka</option>
<option value="option2">Canada</option>
</select>
You just have to define another formControl : 您只需要定义另一个formControl即可:
selectControl : FormControl = new FormControl();
and you can initialize the control : 您可以初始化控件:
ngOnInit(){
this.selectControl.setValue('option')
}
In your template , 在您的模板中,
<form>
<select [formControl]='selectControl' (change)='test()'>
<option [value]='"option"'>Option1</option>
<option [value]='"option1"'>Option2</option>
</select>
</form>
you can check the value changes in the test()
as defined below : 您可以按照以下定义在
test()
检查值更改:
test(){
console.log(this.selectControl.value);
}
You can See the example : https://angular-wytvwr.stackblitz.io 您可以看到示例: https : //angular-wytvwr.stackblitz.io
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.