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

查看:68
本文介绍了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(...).成功不是一个函数 @ 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传统承诺方法成功错误 不推荐使用.请使用标准的 then 方法.

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

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

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

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