Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.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
Angularjs 如何在不调用控制器上的$onInit的情况下使用ui路由器更新路由_Angularjs_Angular Ui Router_Angular Components - Fatal编程技术网

Angularjs 如何在不调用控制器上的$onInit的情况下使用ui路由器更新路由

Angularjs 如何在不调用控制器上的$onInit的情况下使用ui路由器更新路由,angularjs,angular-ui-router,angular-components,Angularjs,Angular Ui Router,Angular Components,我试图在模式打开时动态更新视图上的URL/状态,以及在视图首次显示时自动打开模式。我正在使用1.x版本的UI路由器和AnguarJS组件。我遇到的问题是,当我更新状态时,$onInit()被触发;换句话说,打开模态会导致打开第二个模态 以下是我如何处理改变状态的方法: showModal() { const modal = this.$uibModal.open({ component: 'viewModal', size: 'lg' }) const resetSt

我试图在模式打开时动态更新视图上的URL/状态,以及在视图首次显示时自动打开模式。我正在使用1.x版本的UI路由器和AnguarJS组件。我遇到的问题是,当我更新状态时,
$onInit()
被触发;换句话说,打开模态会导致打开第二个模态

以下是我如何处理改变状态的方法:

showModal() {
  const modal = this.$uibModal.open({
    component: 'viewModal',
    size: 'lg'
  })
  const resetState = () => {
    console.log('resetting state ...')
    this.$state.go('.', {
      id: this.$state.params.id
    }, {
      inherit: false,
      notify: false,
      reload: false,
      location: 'replace'
    })
  }
  modal.opened.then(() => {
    console.log('opening ...')
    this.$state.go('.', {
      foo: 'bar'
    }, {
      notify: false,
      reload: false,
      location: 'replace'
    })
  })
  // The 'catch' is due to the promise being rejected with 'backdrop click'
  // when clicking on the background, though it doesn't always work, but
  // that's another issue entirely
  modal.closed.then(resetState).catch(resetState)
}
下面是相关的
$onInit()
代码

if (this.$state.params.foo) {
  this.showModal()
}
这是路线图

export default function routing ($stateProvider) {
  $stateProvider
    .state({
      name: 'exampleView',
      url: '/example/{id}?foo',
      component: 'exampleComponent'
    })
}

我原以为将
reload
notify
设置为
false
会阻止视图的重新加载,但事实似乎并非如此。是否有更好的方法更新状态而不触发
$onInit
?我应该直接使用
window.location
吗?我希望用户能够在打开模式的情况下加载此视图。我不一定需要历史记录支持,因此我愿意在打开/关闭模式时删除更新URL,但如果可能的话,我更愿意保留它。

修复相对简单,但需要一段时间才能找到。我更新了我的路线,使之看起来像这样

export default function routing ($stateProvider) {
  $stateProvider
    .state({
      name: 'exampleView',
      url: '/example/{id}?foo',
      component: 'exampleComponent',
      params: {
        foo: {
          dynamic: true
        }
      }
    })
}

根据,将参数设置为
dynamic
将防止对参数的任何更改触发状态更改。这类似于应用于状态声明的
reloadOnSearch
属性,但该属性已被弃用。

修复相对简单,但需要一段时间才能找到。我更新了我的路线,使之看起来像这样

export default function routing ($stateProvider) {
  $stateProvider
    .state({
      name: 'exampleView',
      url: '/example/{id}?foo',
      component: 'exampleComponent',
      params: {
        foo: {
          dynamic: true
        }
      }
    })
}

根据,将参数设置为
dynamic
将防止对参数的任何更改触发状态更改。这类似于应用于状态声明的
reloadOnSearch
属性,但该属性已被弃用。

$onInit()
之前验证,如果打开模式以阻止执行我所想的,但AngularUI的(引导)模式类没有该功能,因此,我需要深入DOM,查看body标记上的类。当然可以,但不是很干净。我尝试在控制器上设置一个属性,但在状态更改之间无法保持。请重新计算代码,使模式从服务运行。然后,服务可以跟踪模态的打开/关闭状态。在
$onInit()
之前验证模态是否被打开以防止执行我曾想过,但AngularUI的(引导)模态类没有该功能,因此我需要进入DOM并查看body标记上的类。当然可以,但不是很干净。我尝试在控制器上设置一个属性,但在状态更改之间无法保持。请重新计算代码,使模式从服务运行。然后服务可以跟踪模式的打开/关闭状态。