Kou*_*sha 34 angularjs angular-ui-router
我一直在看这些页面(1,2,3).我基本上想要改变我的$state,但我不希望页面重新加载.
我当前在页面中/schedules/2/4/2014,当我单击按钮并且URL变为时,我想进入编辑模式/schedules/2/4/2014/edit.
我的edit状态很简单$scope.isEdit = true,所以没有必要重新加载整个页面.但是,我确实希望更改$state和/或url更改,以便在用户刷新页面时,它将以编辑模式启动.
我能做什么?
小智 22
参考:https://github.com/angular-ui/ui-router/wiki/Quick-Reference#statetransitiontoto-toparams--options
$state.transitionTo('yourState', params, {notify: false});
Run Code Online (Sandbox Code Playgroud)
b0n*_*b0y 21
对于这个问题,你可以创建一个既没有一个孩子的状态templateUrl也不是controller,和之间预先states正常:
// UPDATED
$stateProvider
.state('schedules', {
url: "/schedules/:day/:month/:year",
templateUrl: 'schedules.html',
abstract: true, // make this abstract
controller: function($scope, $state, $stateParams) {
$scope.schedDate = moment($stateParams.year + '-' +
$stateParams.month + '-' +
$stateParams.day);
$scope.isEdit = false;
$scope.gotoEdit = function() {
$scope.isEdit = true;
$state.go('schedules.edit');
};
$scope.gotoView = function() {
$scope.isEdit = false;
$state.go('schedules.view');
};
},
resolve: {...}
})
.state('schedules.view', { // added view mode
url: "/view"
})
.state('schedules.edit', { // both children share controller above
url: "/edit"
});
Run Code Online (Sandbox Code Playgroud)
这里的一个重要概念是ui-router,当应用程序处于特定状态时 - 当状态为"活动"时 - 它的所有祖先状态也是隐式活动的.
那么,在这种情况下,
schedules(及其templateUrl,controller甚至resolve)仍将保留.| 归档时间: |
|
| 查看次数: |
29543 次 |
| 最近记录: |