如何禁用角UI路由器状态的数据继承 [英] How to disable data inheritance of angular ui router states

查看:104
本文介绍了如何禁用角UI路由器状态的数据继承的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能在角禁用孩子状态 UI路由器继承其父状态的数据?

例如,我有一个家长和孩子的状态如下:

  $ stateProvider.state('父',{
      数据:{
         customData1:你好,
      }
   })
   .STATE('parent.child',{
      数据:{      }
   });

下面的子状态( parent.child )继承其父的数据( customData1 )。
我怎么能继承父数据禁​​用它?


解决方案

虽然我不知道你为什么会喜欢做的..你可以隐藏父类的实现:

继承自定义数据


  

子状态会继承父状态(S),它们可以覆盖数据属性。


  $ stateProvider.state('父',{
      数据:{
         customData1:你好,
         customData2:世界!
      }
   })
   .STATE('parent.child',{
      数据:{
         // customData1从父继承
         //但我们会覆盖customData2
         customData2:UI-路由器!
      }
   });$ rootScope。在('$ stateChangeStart'$,功能(事件,toState){
    VAR问候= toState.data.customData1 ++ toState.data.customData2;
    的console.log(贺卡);    //将打印的Hello World!当父被激活
    //将打印你好UI的路由器!当parent.child被激活
})

How can I disable a child state in angular UI-router from inheriting its parent state's data?

For example, I have a parent and child state as follows:

$stateProvider.state('parent', {
      data:{
         customData1:  "Hello",
      }
   })
   .state('parent.child', {
      data:{

      }
   });

Here the child state(parent.child) inherits the data(customData1) of its parent. How can I disable it from inheriting parent's data?

解决方案

While I am not sure why would you like to do that.. you can hide the parent implementation:

Inherited Custom Data

Child states will inherit data properties from parent state(s), which they can overwrite.

$stateProvider.state('parent', {
      data:{
         customData1:  "Hello",
         customData2:  "World!"
      }
   })
   .state('parent.child', {
      data:{
         // customData1 inherited from 'parent'
         // but we'll overwrite customData2
         customData2:  "UI-Router!"
      }
   });

$rootScope.$on('$stateChangeStart', function(event, toState){ 
    var greeting = toState.data.customData1 + " " + toState.data.customData2;
    console.log(greeting);

    // Would print "Hello World!" when 'parent' is activated
    // Would print "Hello UI-Router!" when 'parent.child' is activated
})

这篇关于如何禁用角UI路由器状态的数据继承的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆