Reload AngularJS Controller

后端 未结 2 753
闹比i
闹比i 2021-02-13 03:28

I\'m a newbie to angularjs.

My problem is that I have a User Controller for handling Login and Logout. I have also another controller to load a header menu for my site.<

2条回答
  •  自闭症患者
    2021-02-13 03:53

    Add this piece of code after the user is authenticated:

    // To refresh the page
    $timeout(function () {
        // 0 ms delay to reload the page.
        $route.reload();
    }, 0);
    

    Don't forget to include $timeout and $route in your controller.

    myapp.controller('HeaderController', ['$scope', '$location', '$window', 'AuthenticationService', '$timeout', '$route',
    function HeaderController($scope, $location, $window, AuthenticationService, $timeout, $route)
    

提交回复
热议问题