zoukankan      html  css  js  c++  java
  • formgroup的用法

    angular中的响应式表单 FormGroup新建,获取Form Group的值

    在HTML中:

    <form [formGroup]="loginFormGroup"> //将这个FormGroup和FormGroup属性绑定起来

    <div class="div_f">
    <div class="div_c_l">
    <span> 邮箱地址</span>
    </div>
    <div class="div_c_r">
    <ion-input type="text" style="97%; font-size: 0.18rem;" clearInput="true" formControlName="email"></ion-input>
    <div class="errorItem" *ngFor="let error of errorMessages.email">
    <div class="error-message" *ngIf="loginFormGroup.controls.email.hasError(error.type)&& (loginFormGroup.controls.email.dirty || submitAttempt)">{{ error.message | translate}}
    </div>
    </div>
    </div>
    <div style="clear:both"></div>
    </div>

    <button id="submit" class="btn_1" (click)="submit()">登录</button>

    </form>

    在类(ts)文件中:
    1.引入
    import { FormBuilder, FormGroup, Validators } from '@angular/forms';

    2.export class CandidateLoginPage implements OnInit {
    errorMessages: any = {
    email: [
    { type: 'required', message: 'Name_Required' }
    ],
    valicationCode: [
    { type: 'required', message: 'Name_Required' }
    ],
    password: [
    { type: 'required', message: 'Name_Required' }
    ],
    };
    loginFormGroup: FormGroup;
    submitAttempt: Boolean = false;
    constructor(private fb: FormBuilder,private candidateLoginService:CandidateLoginService,private navCtrl: NavController,private translateService:TranslateService) {
    this.loginFormGroup = this.fb.group({
    email: ['', Validators.required],
    valicationCode: ['', Validators.required],
    password: ['', Validators.required],
    });
    }
    submit(){
    this.submitAttempt=true;
    }

  • 相关阅读:
    Wolfram常用计算
    soapUI接口关联教程
    时间序列预测线上充值数据
    基于MySQL分析线上充值留存率
    更改用户资料需要完善脚本
    MySQL建立RFM模型
    Scrcpy使用入门
    虾皮Shopee社招面经分享(大数据开发方向),附内推方式
    MySQL Binlog 解析工具 Maxwell 详解
    MySQL Binlog 介绍
  • 原文地址:https://www.cnblogs.com/mmit/p/14119235.html
Copyright © 2011-2022 走看看