Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
210 views
in Technique[技术] by (71.8m points)

AngularJS error .success is not a function

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

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?

main controller:

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');
            });
    };
});
question from:https://stackoverflow.com/questions/33531336/angularjs-error-success-is-not-a-function

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

See 'Deprecation Notice' from $http service documentation:

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

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...