Is there a way to render a view outside of ng-view only when ng-view gets rendered?

644 views Asked by At

I've got user navigation in a partial loaded using ng-include that's outside of the ng-view. I'm also authenticating users and prefetching almost all data necessary for any controller and view in route.resolve.

The issue is that the user navigation partial is displayed using ng-show="currentUser" directive and so when user signs in and currentUser gets set, the navigation partial is shown, but the new view is still waiting to be displayed till all data is fetched in route.resolve. The same situation happens when user signs out - the navigation bar is hidden and the old view is still displayed before user gets redirected and the page for signed out users is displayed.

Is there a way to somehow "link" (re)rendering of the main view (ng-view) and a partial outside of that view? The only other idea I have is to move ng-include directive that loads navigation bar into every template, which is rather annoying.

1

There are 1 answers

1
Nikos Paraskevopoulos On BEST ANSWER

I would make use of the events fired by ng-view ($viewContentLoaded, emitted, see here) and the $route serice ($routeChangeSuccess, broadcasted, see here).

The controller of user navigation partial must set a flag controlling the visibility of the UI depending on the arrival of the appropriate event and the state of the model (currentUser probably).