且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Angular和Firebase中全面展示当前登录的用户

更新时间:2023-12-01 16:44:22

Take a look at the resolve parameter - this exists both in $routerProvider and $stateProvide. resolve resolves the objects (including resolving a promise) and then these objects are available to your controllers. In this case, you "resolve" your loggedInUser variable (by doing whatever you need to do via your authentication service.

$routeProvider
   .when("/someSecuredContent", {
     templateUrl: 'someSecuredContent.html',
     controller: 'SecuredController',
     resolve: {
        loggedInUser: function(MyAuth){
           return MyAuth.loggedIn(); // MyAuth.loggedIn() should return a $q promise
        }
     }
});

Then in the controller, loggedInUser will be injected.

Here's a site with more examples.

相关阅读

推荐文章