2016-04-22 60 views
0

我正在開始使用meanjs堆棧,並且已經達到了一點頭腦,我沒有正確理解谷歌。角度資源注入的問題

我有以下文件: **

(function() { 
'use strict'; 

    angular 
    .module('students') 
    .controller('StudentsListController', StudentsListController); 

    StudentsListController.$inject = ['StudentsService']; 

    function StudentsListController(StudentsService) { 
    var vm = this; 

    vm.students = StudentsService.query(); 
    } 
}()); 

使用這個服務,我能得到學生對象的數組列表,學生控制器,旁邊:

列表 - students.client.controller.js

(function() { 
    'use strict'; 

    angular 
    .module('students') 
    .factory('StudentsService', StudentsService); 

    StudentsService.$inject = ['$resource']; 

    function StudentsService($resource) { 
    return $resource('api/students/:studentId', { 
     studentId: '@_id' 
    }, { 
     update: { 
     method: 'PUT' 
     } 
    }); 
    } 
}()); 

這可按預期工作。 我不明白的是爲什麼當我嘗試在另一個控制器中使用相同的服務時,它似乎無法注入,給我留下一個未定義的StudentsServices變量。 什麼給?

students.client.controller.js

(function() { 
'use strict'; 

    // Students controller 
    angular 
    .module('students') 
    .controller('StudentsController', StudentsController); 

    StudentsController.$inject = ['$scope', '$state', 'Authentication', 'StudentsService']; 

    function StudentsController ($scope, $state, Authentication, student, StudentsService) { 
    var vm = this; 

    vm.authentication = Authentication; 
    vm.student = student; 
    vm.students = StudentsService.query(); 
... 
}()); 

回答

0

您的注射是錯誤的。

'$scope', '$state', 'Authentication', 'StudentsService' 

但是你告訴控制器期望

$scope, $state, Authentication, student, StudentsService