有点新的角度。
我有一个页面,我填写表格并发帖。
然后,我想要完整浏览器重新加载并重定向到名为" created.html"的另一个页面。我在导航栏中有一个下拉列表,在提交后,ddl的可见元素应该是我刚刚在表单中创建的内容。
我被重定向但我的导航栏中的模型未更新。只有手动重新加载。那么......当我重定向到" created.html"网页?
如果我执行以下操作,页面将重定向,然后重新加载,但不是很漂亮。
$window.location.href='/#/created';
location.reload();
stack = angular.module('Stack', ['ngAnimate', 'ui.bootstrap','ui.router']);
stack.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('stack', {
url: '/stack',
templateUrl: 'static/app/stack/stack.html',
controller: 'StackCtrl'
})
.state('created', {
url: '/created',
templateUrl: 'static/app/stack/created.html',
controller: 'StackCtrl'
})
})
stack.controller('StackCtrl',function ($scope,$http,$location,$state,$window) {
$scope.saved = null;
$scope.createStack = function () {
$http({
method: 'POST',
url: "stack",
data: JSON.stringify({"stack_name":$scope.stackName,"stack_namespace":$scope.stackNameSpace}),
headers: { 'Content-Type': 'application/json' }
}).then(function successCallback(response) {
$scope.saved = "saved";
$scope.isSaveDisabled=true;
$state.go('created', {}, {reload: true,inherit: false});
$window.location.href='/#/created';
}, function errorCallback(response) {
$scope.saved = "saved";
$scope.isSaveDisabled=false;
addAlert({ type: 'danger', msg: 'Oh snap! try submitting again.'});
});
}
})
<ul class="nav navbar-nav navbar-right">
<li><a ui-sref="form"><i></i> Form</a></li>
<!-- Single button with keyboard nav -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"> {{selected_stack.stack_name}} <span class="caret"></span></a>
<ul class="dropdown-menu">
<li ng-repeat="stack in stack_not_selected"><a href="#">{{stack.stack_name}}</a></li>
<li role="separator" class="divider"></li>
<li><a ui-sref="stack">Create New Stack</a></li>
</ul>
</li>
</ul>
答案 0 :(得分:1)
试试这个
$state.transitionTo($state.current, {}, { //second parameter is for $stateParams
reload: true,
inherit: false,
notify: true
});
也可以尝试
$state.transitionTo('redirect.second', toParams, {
location:true, inherit:false, reload:true, notify:true });
OR
$state.transitionTo('redirect.second', toParams, { location:true, inherit:true, reload:true, notify:true });