AngularJS: Reload ng-include after user authentication (or a better way to solve issue)

前端 未结 2 931
醉话见心
醉话见心 2021-02-05 20:37

I am really just learning Angular and I am attempting to create an app that limits content access based on authentication. I have the authentication part working (also using the

2条回答
  •  耶瑟儿~
    2021-02-05 21:05

    You can start with raising an event when user login is success on the rootscope using broadcast method

    $rootScope.$broadcast('userLoggedIn',{user:user});
    

    On the appController you can subscribe to the even

    $scope.$on("userLoggedIn",function(event,args) {
         $scope.menuUrl=null;
         $scope.menuUrl="partials/nav.html";
    });
    

    this also implies that change your menuUrl to a property in you controller and html binding.

    Alos, if you can define multiple server views for logged in and anonymous user, then you can just flip the view on user login.

提交回复
热议问题