2014-10-01 38 views
0

導致問題的代碼:約曼角發生器:開發服務器工作正常,但生成後的INFI-消化引發錯誤

angular.module('myApp') 
    .controller('metaCtrl', function ($scope) { 
     $scope.$watch(function(){ return $(document).height() }, function(val){ 
      $scope.config = {minHeight: val} 
     }); 
    }); 

莫名其妙config.minHeight他價值會引起在$觀察者的每次調用功能。

已經花了4個小時試圖調試這個。

任何幫助,非常感謝。

grunt開發服務器和dist文件夾中的服務有什麼不同?

回答

1

我認爲你需要爲依賴注入提供字符串文字。這是因爲縮小後,您的變量名稱將被分解,您的$scope將消失。它在開發服務器中工作,因爲在開發服務器中JS文件沒有被縮小。但在分銷方面,他們是。

angular.module('myApp') 
//inject your $scope using inline annotation so that it doesn't break upon minification. 
.controller('metaCtrl', ['$scope', function ($scope) { 
    $scope.$watch(function(){ return $(document).height() }, function(val){ 
     $scope.config = {minHeight: val} 
    }); 
}]); 
+0

那麼,grunt ng-min已經爲我照顧了。 謝謝 – 2014-10-02 18:43:31

相關問題