javascript - Ionic Controller Function Variable Out Of Scope -
based on tabs template ionic. when click button(ng-click), calls function func()
.controller('accountctrl', function($scope) { $scope.number=3; $scope.func=function(){ number=number+123; } });
when try run func(). chrome reports following.
referenceerror: number not defined
i think because func() cannot find variable number. there way can modify data in function?
the problem there isn't variable called number
in existence. true if had put var number
somewhere declare it.
to modify number
value have declared, make sure reference same object it's part of.
$scope.func = function() { $scope.number = number + 123; // or $scope.number += 123; };
Comments
Post a Comment