How to change HTML element readonly and required attribute in Angular2 Typescript?

前端 未结 1 1110
温柔的废话
温柔的废话 2021-02-11 22:12

For some of my components I would like to change input field readonly and required attributes back and forth.

I\'ve managed to get a running code, that changes both of

相关标签:
1条回答
  • 2021-02-11 22:46

    For bound attributes to be removed they need to be set to null. There was a discussion to change it to remove on false but it was declined, at least for now.

     [required]="isRequired ? '' : null"
    

    or

     [required]="isRequired ? 'required' : null"
    

    Your Plunker produces an error because of missing [] around ngControl.

    See also this Plunker for a working example

    See also Deilan's comments below.

    0 讨论(0)
提交回复
热议问题