I have an app that basically looks like this
<div ui-view="header">
<div ui-view="main">
<div ui-view="footer">
Now, the footer will stay the same for all different states of the app, but the header will change in some states, but also share content in a lot of the states. The only ui-view
that will change across all states is ui-view="main"
.
Currently my $stateProvider
looks like this (footer not implemented yet):
app.config(['$stateProvider', '$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$stateProvider.state('root',{
url: '',
abstract: true,
views: {
'header': {
templateUrl: appHelper.views+'/header.html',
},
}
})
.state('root.home', {
url: '/',
views: {
'header': {
templateUrl: appHelper.views+'/header.html',
},
'main@': {
templateUrl: appHelper.views+'/home.html',
controller: 'HomeController as homeVm',
}
},
resolve: {
posts: function(dataService) {
return dataService.getPosts();
},
artists: function(dataService) {
return dataService.getArtists();
}
}
})
.state('root.artist', {
url: '/artist/:slug',
views: {
'header@': {
templateUrl: appHelper.views+'/artistHeader.html',
controller: 'ArtistController as artistVm',
},
'main@': {
templateUrl: appHelper.views+'/artist.html',
controller: 'ArtistController as artistVm',
}
},
resolve: {
artist: function($stateParams, dataService) {
return dataService.getArtist($stateParams.slug);
}
}
});
}]);
So far, so good. But here’s the catch. During transitions I want to animate all the ui-view
s as one. To make things look cohesive in my case (it’s a fade animation) I would like to put them in a wrapping div and have that div do the fade out/fade in (doing it on each different ui-view
will cause all kinds of ugliness).
What is best practice in this scenario?
Do I wrap them in a ui-view
and hook that up in the $stateProvider
somehow (nested ui-view
s?).
Are there any other ways to do it? Can I listen to $stateChange
and apply classes to my wrapper like ngAnimate
would with an ui-view
? (fade out then wait until entirely faded out with a successful resolve before fading in).
From my googling efforts it seems ui-view
is much preferred when handling animations of the transition type.
$stateChangeStart
and$stateChangeSuccess
events have some odd side effects, so avoid them (at the moment). Until the ui-router has a better way to manage the transition promise other thanevent.preventDefault()
animations through JS will be tricky. Running threeui-views
and animating them all syncronously should not be a problem through pure CSS. Take a look in the ui-routers FAQ section, there is a section dedicated to animating transitions. – Feyheader
is fixed to the top of the viewport during scroll. When the fade out starts it'll reveal the content ofmain
underneath which is not desired. With a wrapper this is obviously not a problem as it'll fade as one single element.. – Worldshaking