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

后端 未结 4 1552
伪装坚强ぢ
伪装坚强ぢ 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:38

    All depends on what you want to achieve. At first look, I would say that pct. 2 is the simplest way to do it:

    
    

    Then, on your component you declare the variable:

    isReadOnly: boolean;
    

    After, you assign the value as you wish:

    // when you want to be read-only
    isReadOnly = true;
    // whe you want to be editable
    isReadOnly = false;
    

提交回复
热议问题