After post some data using Restangular, I want go to another $state and reload data from server using this code:
.directive('ngShowBook', [function(){
return {
restrict : 'E',
controller :
$scope.myFunc = function(){
var bookRelated={ ...};
Restangular.service('books').post(bookRelated).then(function(){
$state.go('parent.main', null, {reload: true}).then(function(){
console.log('ok');
}, function(err) {
console.log(err);// <-this shows error message
});
});
}
.
.
.
and this is my router:
.state('parent', {
abstract: true,
url: '/parent',
templateUrl: 'app/parent/templates/home.html',
resolve: {
books:function(Restangular) {
return Restangular.one('books',10).get();
},
},
}).state('parent.main',{
url: '/main',
templateUrl: 'app/parent/templates/main.html',
})
When I post data, it goes to new $state but without reloading the resolve function. Its error message is:
Error: transition prevented
at $StateProvider.$get (http://localhost:3000/bower_components/angular-ui-router/release/angular-ui-router.js:2867:41)
at Object.invoke (http://localhost:3000/bower_components/angular/angular.js:4473:17)
at http://localhost:3000/bower_components/angular/angular.js:4290:37
at getService (http://localhost:3000/bower_components/angular/angular.js:4432:39)
at Object.invoke (http://localhost:3000/bower_components/angular/angular.js:4464:13)
at http://localhost:3000/bower_components/angular/angular.js:4294:79
at forEach (http://localhost:3000/bower_components/angular/angular.js:336:20)
at createInjector (http://localhost:3000/bower_components/angular/angular.js:4294:3)
at doBootstrap (http://localhost:3000/bower_components/angular/angular.js:1655:20)
at bootstrap (http://localhost:3000/bower_components/angular/angular.js:1676:12)
According this I have to add event.preventDefault(); , but I don't now where I can add it in this case. And is that solve the problem?