Conditionally make input field readonly in Angular 2 or 4: Advice + Best/which way to do it

后端 未结 4 1566
伪装坚强ぢ
伪装坚强ぢ 2021-02-05 00:34

I was attempting to answer someone elses question. And in doing so realised there was quite a bit of uncertainty in my mind about a few things. I\'m hoping someone can provide f

4条回答
  •  故里飘歌
    2021-02-05 01:26

    You need to use the following (Angular 4):

    
    

    If you use att.readonly then the input will always be read-only because the readonly attribute will be present even if its value is false. By using [readonly] Angular will only place the attribute if isReadOnly is true.

    In HTML, the following is sufficient to cause an input to be read-only:

    
    

提交回复
热议问题