ControlValueAccessor with Error Validation in Angular Material

前端 未结 3 783
耶瑟儿~
耶瑟儿~ 2021-01-18 03:37

I am trying to apply Error Validation style with ControlValueAccessor in custom Material Input Textbox. Ever since applying this custom component, all the red border validat

3条回答
  •  旧巷少年郎
    2021-01-18 04:29

    I had the same problem. I tried all and then finally could resolve using this method:

    I added this listener on the custom component. You can also do it 'blur' event.

    @HostListener('focusout', ['$event.target'])
      onFocusout() {
        this.onTouched();
      }
    

    And also calling onTouched when setting any value.

     writeValue(value: any) {
        this.onTouched();
        this.Value = value ? value : '';
    }
    

提交回复
热议问题