我最近使用angularJS(v1.6.x)。当我使用angularJs的$ http服务(GET,DELETE,PUT和POST)时,我遇到了一些问题。这是在我点击任何路线(交换路线多次)并且我回到上一个路线后发生的,然后执行任何操作(创建,编辑或删除)。问题是angularJS?我该怎么做才能阻止这种递归?
这是我尝试的内容:
app.controller('UserComponentControler', ['$rootScope', '$scope', 'UserModel', function($rootScope, $scope, UserModel) {
$rootScope.$on('modal:on:result', function(event, result) {
if (result.status) {
if (result.resultCode === $rootScope.window.CREATE) {
UserModel.create(result.data).then(res => {
if (res.status === 200) {
$scope.page.load(0);
$scope.$emit('modal:on:create:callback', {
created: true
});
}
}, err => {
$scope.$emit('modal:on:create:callback', {
created: false,
message: "Some fields have error with server!"
});
console.log(err);
});
} else if (result.resultCode === $rootScope.window.DELETE) {
userId = result.user.id;
UserModel.destroy(userId).then(res => {
if (res.status === 200) {
$scope.page.load($scope.page.props.current);
$scope.$emit('modal:on:alert', {
deleted: true,
message: {
title: "Message",
body: "User has beed deleted successfully!"
}
});
}
return false;
}, err => {
$scope.$emit('modal:on:alert', {
deleted: false,
message: {
title: "Message",
body: "Server Error Occured!"
}
});
console.log(err);
});
} else if (result.resultCode === $rootScope.window.EDIT) {
UserModel.update(result.data, result.data.id).then(res => {
if (res.status === 200) {
$scope.page.load($scope.page.props.current);
}
}, err => {
$scope.$emit('modal:on:update:callback', {
updated: false,
message: "Some fields have error with server!"
});
console.log(err);
});
}
}
});
}]);

在我的控制器中
{{1}}
我将路由从/ home交换到/ users 7次 this