omer
omer

Reputation: 2623

How can i condition ng-readonly inside textarea

I'm looking for a way to condition a ng-readonly inside an ng-if statement.. i tried it in a few way, this is my latest vesion..

ng-if="note.owner_image === user.image "  ng-readonly="false"

need some assistant..

<textarea 
                  class="wm-textarea-notes"
                  ng-model="noteEdit.note_value" 
                  columns="1"  
                  placeholder="Add a note"
                  ng-readonly="true"
              ng-if="note.owner_image === user.image "  ng-readonly="false"
              ng-if="note.owner_image === "" "  ng-readonly="false


                  ></textarea> 

Upvotes: 7

Views: 25803

Answers (3)

shaheer shukur
shaheer shukur

Reputation: 1167

In latest angular (6/7), you can simply set it using readonly

<mat-form-field>
    <input matInput readonly="true" placeholder="{{placeholder}}" value="{{value}}">
</mat-form-field>

Upvotes: 0

kiswa
kiswa

Reputation: 14987

That's not what ng-if does. It just creates or removes the element based upon the value.

What you want is to have a scope method that makes those tests, let's call it isReadOnly and have your textarea like this:

<textarea
    class="wm-textarea-notes"
    ng-model="noteEdit.note_value" 
    columns="1"  
    placeholder="Add a note"
    ng-readonly="isReadOnly()"></textarea>

So, somewhere in your controller you have to create that method that will return true or false for that textarea to determine its status.

Upvotes: 2

Victor Richa
Victor Richa

Reputation: 441

ng-if is used to hide or show the element based on the condition given. if you want the condition to apply to ng-readonly, you should put it in the ng-readonly attribute:

<textarea 
    class="wm-textarea-notes"
    ng-model="noteEdit.note_value" 
    columns="1"  
    placeholder="Add a note"
    ng-readonly="note.owner_image !== user.image || note.owner_image !== ''">
</textarea> 

Upvotes: 13

Related Questions