I'm having an issue with changing the URL of the page after a form has been submitted.
Here's the flow of my app:
- Routes are set, URL is recognized to some form page.
- Page loads, controller sets variables, directives are fired.
- A special form directive is fired which performs a special form submission using AJAX.
- After the AJAX is performed (Angular doesn't take care of the AJAX) then a callback is fired and the directive calls the
$scope.onAfterSubmit
function which sets the location.
The problem is that after setting the location the nothing happens. I've tried setting the location param to /
as well... Nope. I've also tried not submitting the form. Nothing works.
I've tested to see if the code reaches the onAfterSubmit
function (which it does).
My only thought is that somehow the scope of the function is changed (since its called from a directive), but then again how can it call onAfterSubmit
if the scope changed?
Here's my code
var Ctrl = function($scope, $location, $http) {
$http.get('/resources/' + $params.id + '/edit.json').success(function(data) {
$scope.resource = data;
});
$scope.onAfterSubmit = function() {
$location.path('/').replace();
};
}
Ctrl.$inject = ['$scope','$location','$http'];
Can someone help me out please?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…