Angularjs watch service object

前端 未结 2 1458

Why can\'t I watch a object in a service. Ive got a simple variable working, but a object wont work. http://plnkr.co/edit/S4b2g3baS7dwQt3t8XEK?p=preview

var app          


        
2条回答
  •  不知归路
    2021-02-04 12:36

    injecting whole services into a scope is not something I would do.

    I would prefer to watch a function returning the value :

    $scope.$watch(function() { return test.getData(); }, function(newVal) { 
        /* Do the stuff */
    }, true);
    

提交回复
热议问题