As a beginner with angularjs, I have encountered an issue that has left me puzzled.
I am wondering how I can ensure that when the watch function runs for the second time (on init), the testValue is "changed".
<div ng-controller="MyCtrl"></div>
Here is the javascript code :
var myApp = angular.module('myApp',[]);
function MyCtrl ($scope) {
var testValue = null;
$scope.watchMe = null;
$scope.$watch('watchMe', function () {
console.log('testValue is', testValue);
if(testValue !== null){
console.log('I want to do something different the 2nd time this code runs - but I never get in here...');
}
testValue ="changed";
});
};
For reference, you can view the code on this jsfiddle example.
Thank you for your assistance.