$ auth.login不是一个函数

时间:2015-12-07 17:42:45

标签: javascript angularjs authentication oauth

我使用AngularJS 1.4.6和Satellizer作为oauth。 我按照书面记录了所有内容,但总是得到同样的错误:

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 = 'test@gmail.com';
    $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问题但未找到解决方案。

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

1 个答案:

答案 0 :(得分:0)

我添加到控制器阵列选项

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

    $scope.user = {};
    $scope.user.email = 'test@gmail.com';
    $scope.user.password = 'test';

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