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

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -