Diegote92
Diegote92

Reputation: 65

Model changes not updating the view

I have a button listening for a click event , the idea is to toggle the state when the button is clicked.

The view :

<button  ng-click="nextBtnClicked()" ng-disabled="{{state == 1}}" class="btn">Call</button>

The controller :

app.controller('workStation',['$scope',function($scope)
{
    $scope.state = 0;
    $scope.nextBtnClicked = function()
    {
       $scope.state = 1;
    };
}]

The problem is that I don't see the changes when the button is clicked.I've also tried to execute $apply() but I got the error "Error:[$rootScope:inprog]"

Upvotes: 0

Views: 41

Answers (2)

Gurjaspal
Gurjaspal

Reputation: 74

Use

ng-click="state= !state"

This will toggle the state each time you click the button.

and

ng-disabled="state==1"

to disable the button when state is 1.

Upvotes: 0

tasseKATT
tasseKATT

Reputation: 38490

You don't need to use interpolation.

Use:

ng-disabled="state == 1"

Otherwise:

ng-disabled="{{state == 1}}"

Will be evaulated into:

ng-disabled="false"

Which means the ngDisabled directive will be watching a variable named false on the associated scope.

Upvotes: 3

Related Questions