Angularjs Ui路由器$state.go()不重新加载数据

Angularjs Ui路由器$state.go()不重新加载数据,angularjs,angular-ui-router,Angularjs,Angular Ui Router,使用Restangular发布一些数据后,我想转到另一个$state并使用以下代码从服务器重新加载数据: .directive('ngShowBook', [function(){ return { restrict : 'E', controller : $scope.myFunc = function(){ var bookRelated={ ...}; Res

使用Restangular发布一些数据后,我想转到另一个$state并使用以下代码从服务器重新加载数据:

.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
                     });

                });
           }
.
.
.
当我发布数据时,它会进入新的$state,但不会重新加载resolve函数。其错误信息为:

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)

根据,我必须添加event.preventDefault(),但我现在不知道在这种情况下我可以在哪里添加它。这能解决问题吗?

我遇到了一个类似的问题,并通过执行类似于注释中给出的建议的操作来解决它,即重定向到一个虚拟路由(在本例中,我使用了我的索引路由,因为它实际上没有做任何事情),然后立即重定向回预期的路由。这是一个愚蠢的解决办法,我仍然在寻找更好的东西,但它现在起作用

$state.go('index').then(function(result) {
 $state.go('intended.route', {
  // params
 }, {
  // options
});
查看生成错误的代码,我使用以下代码处理此问题:

if ($state.current.name == 'parent.main')   
    $state.transitionTo($state.current, $stateParams, {reload: true, inherit: true, notify: false})
else
    $state.go('parent.main', null, {reload: true});         

关键点是
notify:false
参数,因此您必须很好地理解其行为的含义(它不会触发$state的事件,带有),但是如果您的场景没有问题,使用此代码,您的state的resolve函数将被调用

{reload:true}
不会重新加载父状态,它只会强制重新加载当前状态。要强制完全重新加载,您可以定义不同的状态,我们将其称为
reloadState
,并创建到
reloadState
的转换,然后立即转换到
parent.main
。谢谢Sulthan。我向“parent.main”添加了一个解析函数,但使用我的代码,数据还没有重新加载。您没有提到从哪个状态调用$state.go,那么我可以帮助您。
if ($state.current.name == 'parent.main')   
    $state.transitionTo($state.current, $stateParams, {reload: true, inherit: true, notify: false})
else
    $state.go('parent.main', null, {reload: true});