为什么角度承诺跟踪器对我不起作用

Why is angular-promise-tracker not working for me?

本文关键字:不起作用 跟踪 承诺 为什么      更新时间:2023-09-26

我已经安装了角度承诺跟踪器,我想我快要让它工作了。 我遇到的问题是"加载"文本没有显示。 数据被提取,并在将其输出到控制台时显示。

因此,ng-show="loadingTracker.active()"似乎不起作用。 我看不出我做错了什么。

任何这方面的帮助将不胜感激 - 一如既往:)

这是我的代码:

.HTML

<button ng-controller="weatherCtrl" 
        ng-model="hotel" 
        class="btn btn-default" 
        ng-click="loadWeather(hotel, $index)">
        {{buttonText}} more</button>
<div collapse="isCollapsed">
    <div class="well well-lg more-detail">
        {{hotel.Description}}
        <br /><br />
            <div>
                <div class="my-super-awesome-loading-box" 
                     ng-show="loadingTracker.active()">
                     Loading..
                </div>                        
            </div>
    </div> 
</div>

.JS

.controller('weatherCtrl', function ($scope, weather, $timeout, promiseTracker){
   $scope.loadingTracker = promiseTracker();
   $scope.buttonText= 'Load'
   $scope.loadedHotelDetails=[];
   $scope.loadWeather = function(hotel, index) {
      // console.log('loadWeather')           
      weather.get({tracker: $scope.loadingTracker}, function (data){
      console.log(data)
      $scope.loadedHotelDetails.push(index)
   })
})

angular.module('weather', [])
    .factory('weather', function($http) {
         var weather = {};
         weather.get = function(params, callback) {
            $http.get('/php/weather.php', {params: {tracker: params.tracker, page: params.page}}).success(function(data) {
             callback(data);
            });
         };
         return weather;
     });

我从未使用过这个模块,但从 github 上的例子来看,我认为你应该在 weather 中这样称呼它:

     weather.get = function(params, callback) {
        $http.get('/php/weather.php', {tracker: params.tracker, page: params.page}).success(function(data) {
         callback(data);
        });
     };

排序好了,这是我需要的代码:

.factory('weather', function($http) {
  var weather = {};
  weather.get = function(params) {
    return $http.get('/php/weather.php', {tracker: params.tracker, page: params.page});
  };
  return weather;
});