1

I'm started to develop in angularJs and I'm struggling on the view partial changing logic.

I'm using ui-router module and I have configured a public and an app abstract state and all of states are child states of these.

// public does not require the user to be authenticated, but app does //

Both states have view partials, header, footer, content, which are related to the login status and of course the content is configured per state.

My problem is that I can't see a logic for placing the in the index.html only in the way like:

<body ng-app="myapp">
...
<div ng-hide="isUserAuthenticated()">
<!-- the public state and its childs' ui-view loading here -->
</div>
<div ng-show="isUserAuthenticated()">
<!-- the app state and its childs' ui-view loading here -->
</div>
...
</body>

I'm running the authentication on each state change in angular.module('myapp',[]).run() method so the authentication is done.

My question is, that is there a better practice for switching between public and app views?

Thanks in advance

update

I'm closing this question. This was a research for any better solution for a problem of un/authorized views strategy in AngularJS.

Btw as the time goes there could be other might better ways to do it so if you have other point of you, feel free to share with us.

  • *Before you'll get your answer, check [this answer](http://stackoverflow.com/a/26702638/1679310) with a clear how to for authentication driven by states and links to plunker and other sources...* – Radim Köhler Feb 07 '15 at 10:07
  • Thank you. I have read this altough my authentication is working well. I'm trying to find out a better strategy to display the ui views in the index.html instead of hiding and showing the layouts :) – Dániel Sebestyén Feb 07 '15 at 10:12
  • Do you know about multi views? https://github.com/angular-ui/ui-router/wiki/Multiple-Named-Views. Because that, with combination discussed above.. is the answer. Root state will provide named views with some default content. Even empty. Each state (state which we want) later will inject its own content there... That is how to combine your stuff with UI-Router power ;) I'd say – Radim Köhler Feb 07 '15 at 10:14
  • Yeah, that is what I'm using now but with conditions because of naming conversion of project. We have header, sidebar, content, footer named views and I was put them with conditions related to authorization. I was just interested if there would be a 'better looking' solution. – Dániel Sebestyén Feb 11 '15 at 08:33

0 Answers0