[英]how i can apply an if confition on a field of formBuilder.group Angular
Im trying to use if condition instead of ?我正在尝试使用if 条件而不是? : for the filed booleanInput using Angular but i don't khow how.
:对于使用Angular提交的布尔输入,但我不知道如何。
ngOnInit(): void {
this.parameterForm = this.formBuilder.group({
booleanInput:
this.ppf.type === 'boolean'
? this.finalValue=== undefined
? (this.finalValue= false)
: this.finalValue
: false
});
}
I did several searches but found nothing.我做了几次搜索,但一无所获。 Can someone help me please?
有谁可以帮助我吗?
As far as I understand, You wanna assign this control a value ie false
or true
.据我了解,您想为此控件分配一个值,即
false
或true
。 You can do this by the following improvements.您可以通过以下改进来做到这一点。 Might be helpful.
可能会有帮助。 Thanks
谢谢
ngOnInit(): void { let finalValue; if(this.ppf.type === 'boolean') { if(finalValue === undefined) { finalValue = false } else { finalValue = this.finalValue } } else { finalValue = false; } this.parameterForm = this.formBuilder.group({ booleanInput: finalValue }); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.