Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript $state.reload()移动到父级';新加坡元州_Javascript_Angularjs_Angular Ui Router - Fatal编程技术网

Javascript $state.reload()移动到父级';新加坡元州

Javascript $state.reload()移动到父级';新加坡元州,javascript,angularjs,angular-ui-router,Javascript,Angularjs,Angular Ui Router,我正在实现某种动态工作流,当我达到某一点时,我必须重新加载状态以呈现HTML并重新实例化控制器才能继续 我发现我第二次调用$state.reload()时没有工作。这是你想要的行为吗?我能做些什么来强制重新加载 if(advanceComplexAction()) { console.log(self.$state); //This is always been printed in console self.$state.reload(); } else { closeAction

我正在实现某种动态工作流,当我达到某一点时,我必须重新加载状态以呈现HTML并重新实例化控制器才能继续

我发现我第二次调用
$state.reload()
时没有工作。这是你想要的行为吗?我能做些什么来强制重新加载

if(advanceComplexAction()) {
  console.log(self.$state); //This is always been printed in console
  self.$state.reload();
}
else {
  closeActionWizard();
}
我正在检查我的控制台,console.log总是打印出来的,但是我的语句
self.$state.reload()
只有在我第一次调用它时才能正确运行

编辑:

我注意到我的url在第一次重新加载时发生了变化,并且正在更改为父url。这一定是问题所在,因为第三次它只重新加载parentState。我不知道怎么解决这个问题

第一次正常工作时,我的url是:

http://localhost:1234/app/parentstate/childstate
使用“重新加载”和所有操作后,它将移动到父状态

http://localhost:1234/app/parentstate
因此,当我再次重新加载时,它只会重新加载父视图。我定义我的路线如下

.config(function($stateProvider, modalStateProvider){
  $stateProvider

.state('app.parentstate',
  modalStateProvider.create({
    animation: true,
    name: 'app.parentsate',
    url: 'apps/parentstate',
    controllerAs: 'parentCtrl',
    controller: 'ParentCtrl',
    windowClass: 'semi-modal semi-modal--XXL',
    templateUrl: function() {
      return 'app/ui/apps/parent/parent.html';
    },
    resolve: {
      //Some resolve function
      }]
    }
  })
)
.state('app.parentstate.childstate',
  modalStateProvider.create({
    animation: true,
    name: 'app.parentstate.childstate',
    url: '/childstate',
    controllerAs: 'childWizardCtrl',
    controller: 'ChildWizardCtrl',
    windowClass: 'semi-modal semi-modal--XL',
    templateUrl: function(){
      return 'app/ui/apps/child/child.html';
    }
  })
)

谢谢

也许你应该试试

$state.transitionTo('current_state', null, {'reload':true});

也许你应该试试这样的东西

$state.transitionTo('current_state', null, {'reload':true});
我明白了

$state.reload(); 
是的别名

$state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: true }); 
“reload:true”刷新父状态!因此,您需要避免使用“$state.reload”

试试看

window.location.reload(true)
我明白了

$state.reload(); 
是的别名

$state.transitionTo($state.current, $stateParams, { reload: true, inherit: false, notify: true }); 
“reload:true”刷新父状态!因此,您需要避免使用“$state.reload”

试试看

window.location.reload(true)

我解决了!问题在于我对modalState的实现。我有一个OnEnter函数,如果我的状态相同或关闭它,它会自动移动到父状态

        modalInstance.result
      .then(function(result) {
        $log.debug('Modal result', result);
      }, function(rejection) {
        $log.debug('Modal dismissed at: ' + new Date() + ' because ' + rejection);
      })
      .finally(function() {
        modalInstance = null;
        if ($state.$current.name === options.name) {
          $state.go('^', $stateParams, { reload: options.reload }); //Here we are moving to parent state
        }
      });

改变这个解决了我的问题。谢谢你的回复

我解决了!问题在于我对modalState的实现。我有一个OnEnter函数,如果我的状态相同或关闭它,它会自动移动到父状态

        modalInstance.result
      .then(function(result) {
        $log.debug('Modal result', result);
      }, function(rejection) {
        $log.debug('Modal dismissed at: ' + new Date() + ' because ' + rejection);
      })
      .finally(function() {
        modalInstance = null;
        if ($state.$current.name === options.name) {
          $state.go('^', $stateParams, { reload: options.reload }); //Here we are moving to parent state
        }
      });


改变这个解决了我的问题。感谢您的回复

一如既往-创建超级简单的
plnkr
示例将使您的问题更有可能得到回答…我一直使用$state.reload()。我有兴趣了解self(self.$state)@DineshSundaraneedi我添加了更多代码并编辑了我发现的内容,所以您只需要重新加载子状态?是的,这就是我想要的。我不知道为什么重新加载后会像往常一样移动到另一个状态-创建超级简单的
plnkr
示例将使您的问题更有可能得到回答…我总是使用$state.reload()。我有兴趣了解self(self.$state)@DineshSundaraneedi我添加了更多代码并编辑了我发现的内容,所以您只需要重新加载子状态?是的,这就是我想要的。我不知道为什么重新加载后会移动到另一个状态否,当我这样做时,我的$state会移动到父状态。您是否用$state.current或您需要的任何内容替换了“current_state”?是的。我不知道我的应用程序在重新加载时发生了什么。注入的$state依赖项将从父项更改为父项,在该依赖项中断时,是否有$stateChangeSuccess或$stateChangeStart事件?否,当我这样做时,我的$state将移动到父项。是否将“current_state”替换为$state.current或任何您需要的内容?是的。我不知道我的应用程序在重新加载时发生了什么。注入的$state依赖项将更改为父应用程序中的$state依赖项,在该依赖项中断时,您的代码中是否有任何$stateChangeSucture或$stateChangeStart事件?这不起作用,因为正在重新加载我的整个应用程序,而我正在丢失一些有价值的信息。我只需要重新加载子状态。我注意到我在整个应用程序中遇到了问题。在重新加载注入的$state后,我尝试重新加载的每个状态都会更改为父状态。这不起作用,因为正在重新加载我的整个应用程序,我会丢失一些有价值的信息。我只需要重新加载子状态。我注意到我在整个应用程序中遇到了问题。在重新加载注入的$state之后,我尝试重新加载的每个状态都会更改为父状态。