无法访问控制器中的$ location

时间:2017-08-23 16:21:24

标签: javascript angularjs

我正在尝试访问我的控制器中的$ location,但我没有运气。下面是我的控制器代码。

bwApp.controller('bidding-controller', [
  '$window', '$scope', '$rootScope', '$firebase', '$location', 
  '$compile', '$interval','$bwAppState', 'bidwrangler_api', 'AuctionService', 
  'CompanyService', 'NavigationService', 'UserService',
  function($window, $scope, $rootScope, $firebase, $location, $compile, $interval,
           $bwAppState, bidwrangler_api, AuctionService, CompanyService, 
           NavigationService, UserService) {

     $scope.toggle_auction = function(item) {
       if ($bwAppState.user.type == "clerk" && !item.listing) {
         $window.location.href = "/clerk/" + item.auction.id + "?item=" + item.id;
       }
       else {
         var restore_pos = null;
         if ($location.search().section == 'itmes') {
           restore_pos = $('.all-items').scrollTop();
           $('.all-items').one('scroll', function(){$('.all-items').scrollTo(restore_pos)});
         }
         else if ($location.search().section == 'user_items'){
           restore_pos = $('#your-items').scrollTop();
           $('#your-items').one('scroll', function(){$('#your-items').scrollTo(restore_pos)});
         }

         NavigationService.update_push_state({item: item.id, section: 'auction'});
      }
    };
  }
]);

当我检查$location.search().section时,我在控制台中一直收到错误消息。如果我在$scope.toggleAuction()之外,我可以访问它。我已经将它正确地包含/注入到控制器中,所以我不明白为什么我无法在$ scope函数中访问它。

我收到的错误如下所示:

enter image description here

0 个答案:

没有答案