Kinda new new angular.
I have a page where I fillout a form and do a post.
I then want to do a full browser reload and be redirect to another page called "created.html". I have a dropdown in the nav bar and after the submit the visible element of the ddl should be what I just created in the form.
I am redirected but model in my navbar is not updated. Only with a manual reload. So...how I do a full reload when redirect to the "created.html" page?
if I do the below the page will redirect and then reload but is not very pretty.
$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>