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
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.