2016-04-22 2 views
0

私はmeanjsスタックを使い始めていますが、私はgoogleを正しく理解していないと思っています。角型リソースインジェクションのトラブル

私は、次のファイルがあります。このサービスを使う**

(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 
を期待するコントローラを言っています