typescript Angular 2 -> 如何使用 FormGroup 隐藏控件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43025499/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Angular 2 -> how to hide controls using FormGroup
提问by haya
Is there any way to control visibility of controls using FormGroup (TypeScript Angular 2).
有什么方法可以使用 FormGroup (TypeScript Angular 2) 控制控件的可见性。
I'm manage to write the following code:
我设法编写以下代码:
this.myDoch.controls['text1'].disable();
but it only blocked the control, I'm looking for hide the contorl.
但它只是阻止了控制,我正在寻找隐藏控制。
Thanks.
谢谢。
回答by The FORCE JB
You can use disabled
like this:
你可以这样使用disabled
:
HTML
HTML
<input [ngClass]="{'hidden': link.controls.title.disabled}" type="text" formControlName="title" />
component.ts
组件.ts
linkArry.controls[0].disable();
CSS
CSS
.hidden {display:none;}
.hidden {display:none;}