2

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>
Tampa
  • 75,446
  • 119
  • 278
  • 425
  • What should happen in the navbar? Can you post the related code to that too? – michelem Nov 01 '15 at 09:17
  • Added the nav bar code. On login I load the nav ddl and load. I want t create a new item and then to be the title. So I do a reload. – Tampa Nov 01 '15 at 09:27

1 Answers1

1

Try this

$state.transitionTo($state.current, {}, { //second parameter is for $stateParams
    reload: true,
    inherit: false,
    notify: true
});

Also try

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

Also see the link Reloading current state - refresh data

Community
  • 1
  • 1
Shohel
  • 3,886
  • 4
  • 38
  • 75