DarkLeafyGreen
DarkLeafyGreen

Reputation: 70466

Disable input on button click in angularjs

HTML

<input type="text" ng-model="email" ng-disabled="button" rquired>
<a class="btn" ng-model="button">edit</a>

So basically I want to enable the input field when the button is clicked. I could do this with some javascript but I want to figure out an easy way for this.

The above example does not work. Any ideas why?

Upvotes: 10

Views: 23862

Answers (1)

joakimbl
joakimbl

Reputation: 18081

You can use ng-click to change the value of button:

<input type="text" ng-model="email" ng-disabled="button" required ng-init="button=true">
<a class="btn" ng-click="button=false">enable edit</a>
<a class="btn" ng-click="button=true">disable edit</a>
<a class="btn" ng-click="button=!button">toggle edit</a>

Upvotes: 17

Related Questions