I have AngularJS with angular-ui-router to have more control over my templates. I have two URL's
- "/timeline"
- "/login"
My idea is to load a parent state which has both the HTML for 1 and 2 and a few partials.
I have a index.html which loads my partial view named "content":
<!doctype html>
<html lang="en" ng-app="myApp" id="ng-app">
<body ng-controller="Login" class="auth-switch">
<div class="body_wrap" ui-view="content"></div>
</body>
</html>
This is what my partial view "content" looks like:
<div ui-view="header">
<div ui-view="profile"></div>
<div ui-view="messages" id="messages"></div>
</div>
<div ui-view="timeline"></div>
<div ui-view="login" ng-controller="Login"></div>
<div ui-view="footer"></div>
I try to create a structure here and want to load those templates. That is what I try to do in my app.js:
// Now set up the states
$stateProvider
.state('content', {
abstract: true,
views: {
"content": { templateUrl: "partials/content.html" }
},
access: access.public
})
.state('content.login', {
url: "/login",
views: {
"messages": { templateUrl: "partials/messages.html" },
"header": { templateUrl: "partials/header.html" },
"login": { templateUrl: "partials/login.html" },
"footer": { templateUrl: "partials/footer.html" }
},
controller: 'Login',
access: access.public
})
.state('content.timeline', {
url: "/timeline",
views: {
"messages": { templateUrl: "partials/messages.html" },
"header": { templateUrl: "partials/header.html" },
"timeline": { templateUrl: "partials/timeline.html" },
"login": { templateUrl: "partials/login.html" },
"footer": { templateUrl: "partials/footer.html" }
},
access: access.user
})
As you can see I created a parent (abstract) state, which has two child states (login and timeline). My main questions are, how can I set this is up clean:
- Do I need states for every partial template instead of using "views"?
- How can I load the "messages" and "profile" templates within the "header" template?
- I only need two URL's is it good to use two states in that case?