【发布时间】:2017-03-30 19:04:47
【问题描述】:
我正在开发一个 AngularJS/Ui-router 项目。我有两种状态:
- 状态1
- state2(state1 的子状态)
国家代码:
app.config(function($stateProvider){
$stateProvider.state('state1', {
url : '/state1',
component : 'state1cpt',
resolve : {
state1data : function(){
return {'x':1, 'y':2, 'z':3};
}
}
});
$stateProvider.state('state1.state2', {
url : '/state2',
component : 'state2cpt'
});
});
每个状态都有一个组件:
app.component('state1cpt', {
bindings : {
state1data : '<'
},
templateUrl : 'state1.html'
});
app.component('state2cpt', {
templateUrl : 'state2.html'
});
以及观点:
index.html
<a ui-sref="state1">State1</a>
<ui-view></ui-view>
state1.html
<h2>State1 x: {{$ctrl.state1data.x}}</h2>
<a ui-sref="state1.state2">State2</a>
<ui-view></ui-view>
state2.html
<h2>State2</h2>
如何将 state1data 对象传递给 state2?更好的方法是什么? (在 state2 的解析中,还是在 state2 的控制器中?)
一个正在奔跑的笨蛋:http://plnkr.co/edit/HDt0f4wzjyUVQ7lEI9YB?p=preview
【问题讨论】:
标签: javascript angularjs angular-ui-router