2015-09-13 60 views
0

我正面臨以下問題,同時將ngResource模塊加載到loginService在angularjs中加載ngResource時遇到問題

Error message: Unknown provider: $ngResourceProvider <- $ngResource <- loginService 

以下是我的代碼。請幫忙。 預先感謝您。

App.js 

var app=angular.module('exampleApp', ['ui.router']); 

app.config(function($stateProvider, $urlRouterProvider) { 

    $urlRouterProvider.otherwise('/login'); 

    $stateProvider 
    .state('login',{ 
     url:'/login', 
     templateUrl:'login.html', 
     controller:'loginController' 
    }) 
    .state('dashboard',{ 
     url:'/dashboard', 
     templateUrl:'dashboard.html' 
    }); 
}); 

app.controller('loginController',['$scope','loginService', function($scope,loginService){ 

    $scope.signin=function() { 

     loginService.authenticate($.param({username: $scope.username, password: $scope.password}),function(authenticationResult){ 

    var authToken = authenticationResult.token; 
     $rootScope.authToken = authToken; 
     console.log('token ::'+authToken); 
    }); 

    } 

}]); 

app.service('loginService', ['$ngResource', function($scope,$resource){ 


return $resource('http://localhost:7001/springangulardemo:action', {}, 
      { 
       authenticate: { 
        method: 'POST', 
        params: {'action' : 'authenticate'}, 
        headers : {'Content-Type': 'application/json'} 
       }, 
      } 
     ); 

}]) 
+0

你包括角resource.js添加ngResource?其解決方案爲 –

回答

0

你並不需要添加服務$ngResource只是在應用模塊

angular.module('exampleApp', ['ui.router','ngResource']); 
+0

。謝謝 – sanjeev