formBuilder验证器模式不起作用

时间:2018-03-29 10:27:17

标签: angular forms validation typescript ionic2

如果密码与formGroup模式不兼容,我正在尝试显示一条消息。

FormGroup init:

this.signupForm = fb.group({
  userName: ['', Validators.compose([Validators.required,Validators.pattern(/^\S*$/),Validators.pattern(`^[a-z0-9_-]{8,15}$`)])],
  image:[''],
  firstName: ['', Validators.required],
  lastName: ['', Validators.required],
  email: ['', Validators.compose([Validators.required, EmailValidator.isValid])],
  password: ['', Validators.compose([Validators.required,Validators.pattern(`^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$`)])],
  confirm: ['', Validators.required]
  }, {
  validator: PasswordValidation.MatchPassword
});

HTML:

      <ion-item no-lines>
        <ion-label floating>
          <ion-icon name="lock"></ion-icon>Password</ion-label>
          <ion-input formControlName="password"  formControlName="password" type="password"></ion-input>
          <ion-icon  class="alert" *ngIf="signupForm.get('password').hasError('pattern')" name="alert-outline" item-right></ion-icon>
      </ion-item>

signupForm.get('password').hasError('pattern')总是假的!

  

signupForm.get('password')。hasError('required')

     

和signupForm.get('password')。感动效果很好

任何人都告诉我我的问题在哪里?

1 个答案:

答案 0 :(得分:0)

没有名为SELECT YEAR(POSBDGT.[PLAN_START_DATE]) as [POSITION_FTE_YEAR], MONTH(POSBDGT.[PLAN_START_DATE]) as [POSITION_FTE_MONTH_NO], CONVERT(varchar(3),DATENAME(month,POSBDGT.[PLAN_START_DATE])) as [POSITION_FTE_MONTH], SUM([TOTALFTE]) AS [TOTALFTE], COMAST.[name] FROM [DBO].[POSITION_FTE] POSFTE WITH (NOLOCK) INNER JOIN [DBO].[POSITION_BUDGET] POSBDGT WITH (NOLOCK) ON POSFTE.POSITION_ID = POSBDGT.POSITION_ID INNER JOIN [DBO].POSITION_LOCATION POSLOC WITH (NOLOCK) ON POSLOC.POSITION_ID = POSFTE.POSITION_ID INNER JOIN [DBO].[country_master] COMAST WITH (NOLOCK) ON COMAST.[country_id] = POSLOC.COUNTRY_ID GROUP BY COMAST.[name], YEAR(POSBDGT.[PLAN_START_DATE]),DATENAME(month,POSBDGT.[PLAN_START_DATE]),MONTH(POSBDGT.[PLAN_START_DATE]) 的图标:

enter image description here

所以你可能正在寻找的是alert-outline,所以你想做...

ios-alert-outline

效果很好...... StackBlitz