Stackoverflow
Stackoverflow

Reputation: 61

AngularJS: How to make field read only inside directive

For my website I have a custom directive for some fields, I would like to dynamically change in the directive whether a particular field should be read only or not based on some values.

Is this possible? and if so how?

Upvotes: 0

Views: 122

Answers (2)

chaitra
chaitra

Reputation: 49

If your custom directive can be used as class i.e,restrict :'C',then

ng-class="{className:[condition]}"

ng-class="{custom-directive:[value =='ABC']}"

Upvotes: 0

Tom Johnson
Tom Johnson

Reputation: 699

I don't think a directive is necessary for what you want to do as ng-readonly can take arguments, you would use it like this;

<input type="search" ng-readonly"variable===true"/>

Hope it helps!

Upvotes: 1

Related Questions