-1

Hi i am developing web site in angularjs. I am using ui-routing. I want to reload state after the user login. I have index.html and app.js. Below is my app.js

var app = angular.module('RoslpApp', ['pascalprecht.translate']);
app.config(function ($stateProvider, $urlRouterProvider, $translateProvider, $translatePartialLoaderProvider)
{
    $urlRouterProvider.otherwise('/HomePage');
    $stateProvider
   .state('Login', {
       url: '/Login',
       templateUrl: 'App/Registration/Login.html',
       controller: 'Login'
   });
});

app.controller('RoslpAppController', ['$scope', function ($scope) {
 var cookieloginid = $cookieStore.get('LoginID');
    if (cookieloginid != null) {
        //This will reoload
        var id = document.getElementById('ProfileDropdown');
        id.innerHTML = $scope.ProfileDropdown = ' <ul>' +
            '<li><a href="#/userProfile">User Profile</a></li>' +
            '<li>test1</li>' +
           ' <li onclick="logout(event)">logout</li>' +
        '</ul>';
        $scope.dp == false;
    }

Below is my login code.

  $http.post(url, sub).then(function (response) {
                        setTimeout(function () { 
//Trigger or reload RoslpAppController controller
LoginSuccess(response); }, 1000);
                    }, function (error) {
                        setTimeout(function () { HideLoader(); }, 1000);
                        toastr.error($filter('translate')(error.data.msg));
                    });

After login success i will get login id and i will store it in cookie. In RoslpAppController controller i want to check if the cookie exists or not on login. May i know how this can be done? Thank you.

Niranjan Godbole
  • 2,135
  • 7
  • 43
  • 90
  • 1
    Possible duplicate of [Reload AngularJS Controller](https://stackoverflow.com/questions/26170625/reload-angularjs-controller) – Sangwin Gawande Jun 07 '17 at 10:46

1 Answers1

0

You have to transition to a state on getting success response from server after your login POST call. To transition to a state use - $state.go("<statename>",{params},{reload : true})

If you don't have any state for RoslpAppController then make one.

Edit after OP's comment :

.state('Roslp', {
    url: '/Roslp',
    templateUrl: 'App/Registration/View.html',
    controller: 'RoslpAppController'
});

In the templateUrl give the view that you want to load after login. Use $state.go("Roslp",{params},{reload : true}) now.

Shoaib Khan
  • 88
  • 1
  • 9