在Angular中从db中删除数据时,转换已取代错误

时间:2016-12-30 20:03:10

标签: javascript angularjs

我有一个基本上像论坛的应用程序。用户可以创建线程然后在里面发表评论。这一切都有效,但当用户删除他的评论时,他会被重定向到主页并显示此错误。

Error: transition superseded
at $StateProvider.$get (https://unpkg.com/angular-ui-router@0.3.2/release/angular-ui-router.js:2909:37)
at Object.invoke (http://localhost/pwa-semes/public/js/angular.js:4842:19)
at http://localhost/pwa-semes/public/js/angular.js:4636:37
at Object.getService [as get] (http://localhost/pwa-semes/public/js/angular.js:4783:32)
at https://unpkg.com/angular-ui-router@0.3.2/release/angular-ui-router.js:3696:17
at Object.invoke (http://localhost/pwa-semes/public/js/angular.js:4842:19)
at http://localhost/pwa-semes/public/js/angular.js:4645:62
at forEach (http://localhost/pwa-semes/public/js/angular.js:357:20)
at createInjector (http://localhost/pwa-semes/public/js/angular.js:4645:3)
at doBootstrap (http://localhost/pwa-semes/public/js/angular.js:1838:20) Possibly unhandled rejection: {}

我有一个ng-click="deleteMessage(message.id)"

的按钮

然后启动这个控制器:

angular.module('messageCtrl', []).controller('messageController', function($scope, $http, Message, $stateParams) {
// object to hold all the data for the new comment form
$scope.messageData = {};

//get id from route
var id = $stateParams.id;
// get all the comments first and bind it to the $scope.comments object
// use the function we created in our service
// GET ALL COMMENTS ==================================================
Message.get(id).then(successCallback);
function successCallback(data) {
    $scope.messages = data.data;
}


// function to handle deleting a comment
// DELETE A COMMENT ====================================================
$scope.deleteMessage = function(id) {

    // use the function we created in our service
    Message.destroy(id).then(successCallbackDestroy);

    function successCallbackDestroy(data){
        Message.get(id).then(successCallback);
    }
};

});

这是api的实际服务

angular.module('messageService', [])

.factory('Message', function($http) {

    return {
        // get all the comments
        get : function(id) {
            return $http.get('api/messages/' + id);
        },

        // destroy a comment
        destroy : function(id) {
            return $http.delete('/pwa-semes/public/api/messages/' + id);
        }
    }

});

我不知道为什么我会收到此错误,或者它是什么意思。我基本上1:1与我对实际Threads相同的文件,这些工作正常。但删除内部注释会引发该错误并重定向回主页,而不是仅仅删除页面中的注释。实际的删除工作,它消失了,但有这个错误。你知道该怎么办吗?

编辑:这是我的状态转换

(function() {

'use strict';

angular
    .module('website', ['ui.router', 'satellizer', 'threadService', 'threadCtrl', 'messageService', 'messageCtrl'])
    .config(function($stateProvider, $urlRouterProvider, $authProvider) {

        // Satellizer configuration that specifies which API
        // route the JWT should be retrieved from
        $authProvider.loginUrl = 'pwa-semes/public/api/authenticate';

        // Redirect to the auth state if any other states
        // are requested other than users
        // $urlRouterProvider.otherwise('/login');

        $stateProvider
            .state('login', {
                url: '/login',
                templateUrl: 'partials/login.html',
                controller: 'authController as auth'
            })
            .state('register', {
                url: '/register',
                templateUrl: 'partials/register.html'
            })
            .state('users', {
                url: '/users',
                templateUrl: 'partials/users.html',
                controller: 'userController as user'
            })
            .state('message', {
                url: '/message/{id}',
                templateUrl: 'partials/message.html'
            })
            .state('homepage', {
                url: '/homepage',
                templateUrl: 'partials/homepage.html'
            })
            .state('index', {
                url: '',
                templateUrl: 'partials/homepage.html'
            });
    });
})();

0 个答案:

没有答案