angular.js - angular服务里取到的值,怎么在服务外同步该值?
漂亮男人
漂亮男人 2017-05-15 17:09:27
0
1
572
monitorService.getFMCMonitor({ scenario: 'indoor'},function(res){
     $scope.data = res;
 });
 //$scope.$watch('data',(n,o)=>console.log(n));
 console.log($scope.data); ==> undefined

monitorService是一个获取后台数据的service,如果不用$watch$timeout,怎么同步$scope.data的值?就是一打印$scope.data,就是服务里取到的值,而不是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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!