Mishu Lojan
Mishu Lojan

Reputation: 139

Ng-change not working properly in angularjs

I'm using a input type= number , but I cannot get my ng-change function to call.

<input type="number" name="numero" placeholder="1234 1234 1234 1234" ng-model="card.numero" ng-change="validar_card()" required>

my controller

$scope.validar_card=function () {
    console.log(card.numero);
  }

Upvotes: 1

Views: 352

Answers (2)

Sajeetharan
Sajeetharan

Reputation: 222552

 <input type="number" ng-model="count" ng-change="change()"  />

Controller

 $scope.validar_card=function(){
        $scope.count++;
    }

EDIT:

With your update, you are not using the $scope variable.It should be

$scope.validar_card=function () {
    console.log($scope.card.numero);
}

DEMO

Upvotes: 0

Gustavo Gabriel
Gustavo Gabriel

Reputation: 1296

In your controller you forgot to put $scope in your console.log:

console.log($scope.card.numero);

Also dont forget to put $scope.card = {} in the beggining of the controller. Below fiddle:

http://jsfiddle.net/twizzlers/5f411u2e/1/

Upvotes: 1

Related Questions