亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Angular2驗證器,它依賴于多個表單字段

Angular2驗證器,它依賴于多個表單字段

largeQ 2019-11-06 11:10:47
是否可以創建一個可以使用多個值來確定我的字段是否有效的驗證器?例如,如果客戶首選的聯系方式是通過電子郵件,則必須填寫電子郵件字段。謝謝。更新了示例代碼...    import {Component, View} from 'angular2/angular2';    import {FormBuilder, Validators, formDirectives, ControlGroup} from 'angular2/forms';    @Component({        selector: 'customer-basic',        viewInjector: [FormBuilder]    })    @View({        templateUrl: 'app/components/customerBasic/customerBasic.html',        directives: [formDirectives]    })    export class CustomerBasic {        customerForm: ControlGroup;        constructor(builder: FormBuilder) {            this.customerForm = builder.group({                firstname: [''],                lastname: [''],                validateZip: ['yes'],                zipcode: ['', this.zipCodeValidator]                 // I only want to validate using the function below if the validateZip control is set to 'yes'            });        }        zipCodeValidator(control) {            if (!control.value.match(/\d\d\d\d\d(-\d\d\d\d)?/)) {                return { invalidZipCode: true };            }        }    }
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 777 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號