gpt4 book ai didi

angularjs - 如何禁用 Angular ui 路由器状态的数据继承

转载 作者:行者123 更新时间:2023-12-03 00:03:00 25 4
gpt4 key购买 nike

如何禁止 Angular UI-router 中的子状态继承其父状态的数据?

例如,我的父子状态如下:

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

}
});

这里子状态(parent.child)继承了其父状态的数据(customData1)。如何禁止它继承父级的数据?

最佳答案

虽然我不确定您为什么要这样做..您可以隐藏父实现:

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

关于angularjs - 如何禁用 Angular ui 路由器状态的数据继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27183310/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com