2015-11-08 4 views
0

My App выглядитAngularJS: TypeError: Не удается прочитать свойство 'get' of undefined?

var app = angular.module('cockpit', ['tenantService', 'ngMaterial', 'ngMdIcons']); 

Мой контроллер выглядит

angular.module('cockpit').controller('TenantController', ['TenantService', function($scope, TenantService){ 
    $scope.tenants = TenantService.get(); 
    console.log('TenantController started', $scope.tenants); 
}]); 

и моя служба выглядит

angular.module('tenantService', []) 
    .service('TenantService', function() { 
    this.get = function() { 
     return [ 
     { 
      'name': 'fakeTenant', 
      'freeMemory': '45', 
     }, 
     ] 
    } 
}); 

импортировать зависимости правильно, как

<script src="src/cockpit/app.js"></script> 
    <script src="src/cockpit/controllers/tenant_controller.js"></script> 
    <script src="src/cockpit/services/tenants.js"></script> 

и в моем HTML, я

 <div ng-controller="TenantController"> 
     {{tenants}} 
     </div> 

Но когда я вижу console я вижу

TypeError: Cannot read property 'get' of undefined 
    at new <anonymous> (tenant_controller.js:2) 
    at Object.e [as invoke] (angular.js:4169) 
    at G.instance (angular.js:8422) 
    at angular.js:7677 
    at r (angular.js:330) 
    at J (angular.js:7676) 
    at g (angular.js:7062) 
    at J (angular.js:7701) 
    at g (angular.js:7062) 
    at g (angular.js:7065) 

Почему зависимость не вводили?

ответ

0

Проблема была инъекции в контроллере, следующие фиксированные его

angular.module('cockpit').controller('TenantController', function($scope, TenantService){ 
    $scope.tenants = TenantService.get(); 
    console.log('TenantController started', $scope.tenants); 
});