Questions tagged «angular2-formbuilder»

5
formControlName和FormControl有什么区别?
我正在使用ReactiveFormsModuleAngular2创建包含表单的组件。这是我的代码: foo.component.ts: constructor(fb: FormBuilder) { this.myForm = fb.group({ 'fullname': ['', Validators.required], 'gender': [] }); } foo.component.html(带有[formControl]): <div class="fields"> <div class="field"> <label>Fullname*</label> <input type="text" [formControl]="myForm.controls.fullname"/> </div> </div> <div class="inline fields"> <label for="gender">Gender</label> <div class="field"> <div class="ui radio checkbox"> <input type="radio" name="gender" checked="" tabindex="0" class="hidden" [formControl]="myForm.controls.gender"> <label>Male</label> </div> </div> <div class="field"> <div …

10
ngModel不能用于通过父formGroup指令注册表单控件
升级到RC5后,我们开始出现此错误: ngModel cannot be used to register form controls with a parent formGroup directive. Try using formGroup's partner directive "formControlName" instead. Example: <div [formGroup]="myGroup"> <input formControlName="firstName"> </div> In your class: this.myGroup = new FormGroup({ firstName: new FormControl() }); Or, if you'd like to avoid registering this form control, indicate that …

19
反应形式-将字段标记为已触摸
我无法找出如何将所有表单字段都标记为已触摸。主要问题是,如果我不触摸字段并尝试提交表单-验证错误未显示。我的控制器中有这段代码的占位符。 我的想法很简单: 用户点击提交按钮 所有字段都标记为已触摸 错误格式化程序重新运行并显示验证错误 如果有人有其他想法如何在提交时显示错误而不执行新方法,请与他人分享。谢谢! 我的简化形式: <form class="form-horizontal" [formGroup]="form" (ngSubmit)="onSubmit(form.value)"> <input type="text" id="title" class="form-control" formControlName="title"> <span class="help-block" *ngIf="formErrors.title">{{ formErrors.title }}</span> <button>Submit</button> </form> 而我的控制器: import {Component, OnInit} from '@angular/core'; import {FormGroup, FormBuilder, Validators} from '@angular/forms'; @Component({ selector : 'pastebin-root', templateUrl: './app.component.html', styleUrls : ['./app.component.css'] }) export class AppComponent implements OnInit …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.