2016-12-22 26 views
0

ここで自分のコードで何が問題なのか尋ねたいですか?Angularjs:サービスが定義されていません

インデックス:

// ng-app="app" and ng-controller="Student" is already injected 

<script src="app/js/jquery/jquery-3.1.1.min.js"></script> 
<script src="app/js/angularjs/angular.min.js"></script> 
<script src="app/controller/app.js"></script> 
<script src="app/service/student-service.js"></script> 
<script src="app/controller/student-controller.js"></script> 
<script src="app/css/bootstrap/js/bootstrap.min.js"></script> 

app.js:

(function() { 

'use strict'; 
angular.module('app', [ 
    'Student', 
    'StudentService' 
]); 

})(); 

学生-controller.js:

angular.module('Student', ['StudentService']) 
    .controller('Student', ['$scope', '$http', 'StudentService', 
     function($scope, $http, $studentService) { 

     // a function here which calls studentService 

     }]); 

学生-service.js:

angular.module('StudentService', []) 
    .factory('StudentService', ['$http', '$q', 
     function($http, $q) { 

      return { 
       getStudentData : getStudentData 
      } 

      // getstundetData function here 


}]); 

私のコントローラ内の関数でstudentServiceを呼び出すと、studentServiceが定義されていないというエラーが表示されます。私は本当に間違っていることを知っていないが、私は私のdependecyの流れが正しいと思う。 。

index->​​ app.js-> controller->サービス

あなたは私の男を助けることはできますか?ありがとう。 。 。

答えて

1

変更順序、app.jsは、他の2つのモジュールにdepdendentであるため、

<script src="app/service/student-service.js"></script> 
<script src="app/controller/student-controller.js"></script> 
<script src="app/controller/app.js"></script> 
+0

ない進捗のSIR sajee :( –

+0

.controllerに$studentServiceのコントローラ注入( [ – Sajeetharan

+0

Omg!ありがとうsir sajee私の目は私を裏切っています:( –

2

変化StudentService

.controller('Student', ['$scope', '$http', 'StudentService', 
     function($scope, $http,StudentService) { 

     // a function here which calls studentService 

     }]); 
+0

ありがとうございました! :) –

関連する問題