Short answer to your "Why?" is that $watch takes a function as a second parameter while you're passing reactToDataChange($rootScope,$location)
which is a function call and returns undefined
. It's easy to fix it by modifying reactToDataChange
:
function reactToDataChange($rootScope, $location) {
return function(){
console.log("yyy")
console.log($rootScope.jsonData)
// ...
}
}
By the way your repeat is overcomplicated. Why not try this:
var rep = function(){
$timeout(function(){
$rootScope.jsonData = DataService.getData();
rep();
},delaytime);
}
rep();