When using Angular, I encountered an issue where the user was not redirected to the view page after submitting a form.
To handle this, I attached the following function to the scope:
$scope.create = function () {
return $scope.customer.$save({}, function (obj) {
Msg.show('Customer created');
return $location.path('customer/'+obj.id);
})
};
This method successfully redirects the user as intended.
To further organize the code, I decided to encapsulate the logic within a service.
...
this.create = function (object, params, callback) {
return function () {
return object.$save(params, function (obj) {
Msg.show('Object created');
if ( callback instanceof Function ) {
return callback(obj);
}
});
};
};
....
I then attached the service to the scope in this way:
$scope.create = ResourceActions.create($scope.customer, {}, function (customer) {
return $location.path('customers/'+customer.id);
});
However, after submission, the user is only "redirected" for a split second before the path changes back. It's puzzling and unclear what is causing this behavior.