Sankar
Sankar

Reputation: 7107

ng-disabled not working in button

I'm learning angular stuffs and got stuck up in ng-disabled directive. Below is my code.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
<html ng-app>

<body>
  <input type="text" ng-model="myName" ng-change="txtEnable()" />
  <span>{{ (myName.length % 2) === 0 }}</span>
  <button ng-disabled="{{ (myName.length % 2) === 0 }}">button</button>
</body>

</html>

when i change the value in text, the span element get updated but the button doesn't. what i did wrong here?

Upvotes: 0

Views: 1030

Answers (1)

Sankar
Sankar

Reputation: 7107

Got it! The problem is with curly braces {{}}.

Curly braces({{}}) to bind expressions to elements is built-in Angular markup.

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.18/angular.min.js"></script>
<html ng-app>

<body>
  <input type="text" ng-model="myName" ng-change="txtEnable()" />
  <span>{{ (myName.length % 2) === 0 }}</span>
  <button ng-disabled="(myName.length % 2) === 0">button</button>
</body>

</html>

Upvotes: 1

Related Questions