AngularJS错误.success不是函数

Mih*_*šič 34 angularjs

我已经构建了一个工厂来处理我的控制器的功能,但不知何故控制器在其中一个函数上返回错误:

错误:Auth.getUser(...).成功不是函数@ http:// localhost:8080/app/controllers/mainCtrl.js:10:1
...

我不知道这里发生了什么,其余的功能似乎工作得很好?

主控制器:

angular.module('mainCtrl', [])
.controller('mainController', function($rootScope, $location, Auth) {
    var vm = this;
    vm.loggedIn = Auth.isLoggedIn();
    $rootScope.$on('$routeChangeStart', function() {
        vm.loggedIn = Auth.isLoggedIn();
        Auth.getUser()
            .success(function(data) {
                vm.user = data;
            });
    });
    vm.doLogin = function() {
        Auth.login(vm.loginData.username, vm.loginData.password)
            .success(function(data) {
                $location.path('/users');
            });
    };
});
Run Code Online (Sandbox Code Playgroud)

avi*_*ivr 99

请参阅$ http服务文档中的 " 弃用通知 " :

$ http遗留承诺方法成功错误已被弃用.使用标准方法来代替.

您可以在有关$ q文档中了解有关这些方法的更多信息.

  • 不是所有的英雄穿着斗篷.谢谢 (4认同)

Dev*_*per 15

这是代码

已删除的代码

$http(  
{  
    method: 'POST',  
    url: '/Home/CreateCustomer',   /*You URL to post*/
    data: $scope.cust   /*You data object/class to post*/
}).success(function (data, status, headers, config)  
{  

}).error(function (data, status, headers, config)  
{  

}); 
Run Code Online (Sandbox Code Playgroud)

允许的代码 Angular $ http docs

$http(
    {
       method: 'POST',
       url: '/Home/CreateCustomer',  /*You URL to post*/
       data: $scope.cust  /*You data object/class to post*/
    }).then(function successCallback(response) {
       // this callback will be called asynchronously
       // when the response is available


    }, function errorCallback(response) {
       // called asynchronously if an error occurs
       // or server returns response with an error status.

});
Run Code Online (Sandbox Code Playgroud)