angular.js - How to synchronize the value obtained from the angular service outside the service?
漂亮男人
漂亮男人 2017-05-15 17:09:27
0
1
643
monitorService.getFMCMonitor({ scenario: 'indoor'},function(res){
     $scope.data = res;
 });
 //$scope.$watch('data',(n,o)=>console.log(n));
 console.log($scope.data); ==> undefined

monitorService is a service that obtains background data. If $watch is not used, how to synchronize the value of $timeout with $scope.data? Just print $scope.data, which is the value obtained from the service, not undefined

漂亮男人
漂亮男人

reply all(1)
黄舟

Because it is asynchronous, the ajax request does not return when you print, so it is naturally undefined.

You can do this, pass a callback as a parameter, or a promise, both are fine.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template