2015-12-07 15 views
0

我对oauth使用AngularJS 1.4.6和Satellizer

angular.js:12450 TypeError: $auth.login is not a function 

的login.html:

<div class="form-group"> 
    <input type="email" class="form-control underline-input" placeholder="Email" ng-model="user.email" required> 
    </div> 

    <div class="form-group"> 
    <input type="password" placeholder="Password" class="form-control underline-input" ng-model="user.password" required> 
    </div> 

    <div class="form-group text-left mt-20"> 
    <button type="submit" class="btn btn-greensea b-0 br-2 mr-5" ng-click="login()" ng-disabled='form.$invalid'>Login</button> 
    <label class="checkbox checkbox-custom checkbox-custom-sm inline-block"> 
     <input type="checkbox"><i></i> Remember me 
    </label> 
    <a ui-sref="core.forgotpass" class="pull-right mt-10">Forgot Password?</a> 
    </div> 

</form> 

登录控制器:

.controller('LoginCtrl', function ($scope, $auth) { 

    $scope.user = {}; 
    $scope.user.email = '[email protected]'; 
    $scope.user.password = 'test'; 

    $scope.login = function() { 
     $auth.login($scope.user).then (
     function (response) { 
      console.log(response); 
     }, 
     function (error) { 
      console.log(error); 
     } 
    ) 
    } 

app.js:

书面但总是得到同样的错误 我做的一切
 .config(['$stateProvider', '$urlRouterProvider', '$authProvider', function($stateProvider, $urlRouterProvider, $authProvider) { 

      $authProvider.loginUrl = '/auth/login'; 
... 

我尝试了不同的解决方案,研究github问题但未找到解决方案。

什么是我的错?我该如何解决它?

回答

0

我添加到控制器阵列选项

.controller('LoginCtrl', ['$scope','$auth', function ($scope, $auth) { 

    $scope.user = {}; 
    $scope.user.email = '[email protected]'; 
    $scope.user.password = 'test'; 

    $scope.login = function() { 
     $auth.login($scope.user).then (
     function (response) { 
      console.log(response); 
     }, 
     function (error) { 
      console.log(error); 
     } 
    ) 
    }]