AngularJS 错误 .success 不是函数 [英] AngularJS error .success is not a function

查看:31
本文介绍了AngularJS 错误 .success 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经建立了一个工厂来处理我的控制器的功能,但控制器以某种方式返回了其中一个功能的错误:

I have build a factory to handle the functions for my controller, but somehow the controller returns an error on one of the functions:

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

Error: Auth.getUser(...).success is not a function @http://localhost:8080/app/controllers/mainCtrl.js:10:1
...

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

I have no idea what's going on here, the rest of the functions seem to be working fine?

主控制器:

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');
            });
    };
});

推荐答案

请参阅 $http 服务文档:

See 'Deprecation Notice' from $http service documentation:

$http 遗留的承诺方法 successerror 已经已弃用.改用标准的 then 方法.

The $http legacy promise methods success and error have been deprecated. Use the standard then method instead.

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

You can learn more about these methods in the documentation about $q.

这篇关于AngularJS 错误 .success 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆