2017-03-10 12 views
1

これをデバッグしようと数時間を費やしましたが、実際のブレークスルーはありません。私のconsole.logsはロード順を正しく出力します。
- アプリ
- 工場
- コントローラ
私は(私は現時点では縮小化ではないんだが)、私の依存関係に注釈を付けますよ。工場出荷時のサービスは常に定義されていません

ここで間違っているものはありますか?

エラー
enter image description here

アプリ

(function() { 
'use strict'; 
console.log("running app"); 
var app = angular.module('InventoryProductApp', []).config(function ($logProvider) { 
    $logProvider.debugEnabled(true); 
}); 
angular.element(document).ready(function() { 
    var app = document.getElementById('InventoryProductApp'); 
    angular.bootstrap(angular.element(app), ['InventoryProductApp']); 
}); 
})(); 

コントローラ

(function() { 
'use strict'; 
angular.module('InventoryProductApp').controller("LocationsController", ['$scope', '$log', 'LocationsFactory' 
, function ($scope, $http, $log, LocationsFactory) { 
    console.log("running controller"); 
    $scope.locations = null; 
    $scope.loading = false; 

    //private methods ------------------------------------------------------------------------------------------------------------------------------------------------------------- 

    var fetchLocationData = function (inventoryId) { 
     $scope.loading = true; 
     console.log(LocationsFactory); 
     var promise = LocationsFactory.getLocationData(inventoryId); 

     promise.then(function (data) { 
      $scope.loading = false; 

      if (data.success) { 
       $scope.locations = data.locations; 
      } 
      else 
      { 
       $log.error('There was an error getting location data'); 
      } 

     }, function (data) { 
      $scope.loading = false; 
      $log.error('There was an error getting location data'); 
     }); 
    } 

    //end private methods --------------------------------------------------------------------------------------------------------------------------------------------------------- 


    //public methods -------------------------------------------------------------------------------------------------------------------------------------------------------------- 

    var init = function (inventoryId) { 
     console.log('inventoryId', inventoryId); 
     fetchLocationData(inventoryId); 
    } 
    //end public methods ---------------------------------------------------------------------------------------------------------------------------------------------------------- 

    init(inventoryId); // inventoryId is found in the partialView _inventoryLocationDistribution 
}]); 
})(); 

工場

(function() { 
'use strict'; 

angular.module('InventoryProductApp').factory('LocationsFactory', ['$http', '$q', '$log', function ($http, $q, $log) { 
    console.log("running factory"); 
    return { 
     getLocationData: function (inventoryId) { 
      var def = $q.defer(); 

      $http.get('/butthead', { 
       params: { 
        inventoryId: inventoryId 
       } 
      }).then(function (response) { 
       def.resolve({ 
        success: true, 
        locations: data.locations 
       }); 
      }, function (response) { 
       $log.error('failed to fetch data', response); 
       def.resolve({ 
        success: false, 
        redirect: response.redirect 
       }); 
      }); 

      return def.promise; 
     } 
    } 
}]); 
})(); 

スクリプトロード順

お使いのコントローラで
<script src="~/theme/modern/assets/global/plugins/angularjs/angular.min.js"></script> 
<script src="~/App/Inventory/Product/ProductApp.js"></script> 
<script src="~/App/Inventory/Product/LocationsFactory.js"></script> 
<script src="~/App/Inventory/Product/LocationsController.js"></script> 
+0

エラーを画像ではなくテキストとして送信してください。 –

+1

ng-annotateを使用し、この醜い、冗長でエラーが発生しやすい配列表記を使用してください。 –

答えて

2

:あなたはLocationsFactory引数ISN」を意味し、あなたの依存性の注入で'$http'、欠けている

angular.module('InventoryProductApp').controller("LocationsController",  
    ['$scope', '$log', 'LocationsFactory', function ($scope, $http, $log, LocationsFactory) { 

まったく満たされていない。

+0

あなたは男です! 2分でマークされます。 – Adrian

関連する問題