-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.

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. I do not have state for RoslpAppController because that is in app.js file. May i know how can i create state to it?
I have created a plunker. plnkr.co/edit/ZJJZLqJWRPOk4SKlvAa8?p=preview On login success i want to reload controller RoslpAppController

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.