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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 04:23:17  来源:igfitidea点击:

Angular 2 -> how to hide controls using FormGroup

angulartypescript

提问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 disabledlike 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;}

回答by Gili Yaniv

You can use the 'disabled' css selector. For example :

您可以使用 'disabled' css 选择器。例如 :

.my-input:disabled {
    display:none;
}

You can read about it here.

你可以在这里阅读它。