Javascript 角度6如何进行所有输入';表单中的不可编辑元素
是否有办法禁用并使所有字段不可编辑Javascript 角度6如何进行所有输入';表单中的不可编辑元素,javascript,angular,angular-material,Javascript,Angular,Angular Material,是否有办法禁用并使所有字段不可编辑 (input/mat select/textfield/option/input/mat复选框等)在表单中 this.formGroupName.controls[controlNmae].disable(); this.formGroupName.disable() 通过在角度/角度材质中仅告知父div名称? (无法编辑它们) this.formGroupName.controls[controlNmae].disable(); this.form
(input/mat select/textfield/option/input/mat复选框等)
在表单中
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
通过在角度/角度材质中仅告知父div名称?
(无法编辑它们)
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
M
夫人。
...........................
.......... 例子
如果您使用的是反应式表单,您可以像这样通过编程实现(一个接一个的方法):
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
例如:this.formGroupName.controls['lastName'].disable()
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
要一次禁用所有功能,请执行以下操作:
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
在您的情况下,请执行:this.leaseholdeform.disable()
要将其返回,请执行:this.leaseholdeform.enable()
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
您可以创建这样的函数,并在调用createLeaseHoldePerform()
后调用它:
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
有关更多信息,请阅读。创建一个FormGroup,如下所述:
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
然后,以编程方式获取formGroup
实例,并对其调用.disable()
,如下所示:
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
this.leaseholdeform.disable()
在html模板中使用disable
属性
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
<mat-form-field>
<input matInput upperCaseInput placeholder="Nom d'usage" formControlName="lastName" disable>
</mat-form-field>
禁用和不可编辑不一定是一回事。禁用的输入当然也不可编辑,但它有一个独特的外观-灰显,看起来“禁用”。只读输入看起来与普通输入相同,但不可编辑。因此,您必须询问您是希望您的控件实际上被禁用还是只读
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
如果您只需要只读,只需使用
的只读
属性并将其绑定到控制器中的变量即可。例如:
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
export class LeaseholderComponent implements OnInit, IFormDirtyWarningComponent {
@Input() editable: boolean = false; // doesn't have to be an @Input
...
}
<form [formGroup]="leaseholderForm" (ngSubmit)="onSubmit()">
<mat-form-field>
<input matInput [readonly]="!editable" upperCaseInput placeholder="Nom d'usage" formControlName="lastName">
</mat-form-field>
...
</form>
由于disabled属性在某些组件上不起作用,我所做的是-在css上设置指针事件:none,以覆盖div内容中的所有组件
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
这是我的CSS代码:
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
.disabledDiv {
pointer-events: none;
opacity: 0.4; }
<div class="content-area" [ngClass]="{disabledDiv: !isActiveDiv}">
<!-- other components here (input/select/etc.) -->
<div>
这是我的HTML:
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
.disabledDiv {
pointer-events: none;
opacity: 0.4; }
<div class="content-area" [ngClass]="{disabledDiv: !isActiveDiv}">
<!-- other components here (input/select/etc.) -->
<div>
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
在输入标记内的HTML文件中使用readonly属性。
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
在第八章中没有为我工作。因此,我在HTML中添加了一个“readonly”属性,然后在.ts文件中更改了它的值
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
inside.html文件
this.formGroupName.controls[controlNmae].disable();
this.formGroupName.disable()
<input formControlName="email" matInput type="email" #email email="true" [readonly]="email_readonly" />
email_readonly = false;
yourFunction()
{
this.email_readonly = true;
}
是的,我使用反应式表单,我更新问题。禁用()不起作用。你能提供你的组件控制器的代码吗?完成了,我不确定。禁用()将表单的所有字段都设置为不可编辑,我认为禁用formI控件我同意。如图所示,这应该是可行的@AnouarMokhtari-控制台中没有错误?请记住,禁用的不会随表单一起提交,而只读的会随表单一起提交。Buenaso!这就是我需要的!非常感谢。disabled属性不应与角度反应形式的输入元素一起使用。应该禁用表单控件:control=new FomrControl({'value',disabled:true},[validators])代码>这是最好的解决方案,因为它不会将字段标记为无效。尽量不要使用代码图像来回答问题-代码是文本,为什么不将其作为文本发布?不熟悉指针事件。但这是否也能防止禁忌?