I created a working example here . It comes from Q and A
This will be the corrected def state:
.state('base', { abstract: true, views: { '': { template: '<ui-view></ui-view>', }, /* nav: { templateProvider: function ($templateFactory, User, $stateParams){ if(User.exists()){ var url = '/static/html/navs/' + User.get.type + '.html'; return $templateFactory.fromUrl(url); } else{ return false; } } },*/ nav: { templateProvider: ['User', '$templateRequest', function(User, templateRequest){ var tplName = 'templates/templateNotExists.html'; if(User.exists) { tplName = 'templates/templateExists.html'; } return templateRequest(tplName); }], }, } })
As we can see, we use a new function called '$templateRequest' to get the html template from the server based on the URL.
and these are controllers and services
.controller('loginController', ['$scope', 'User', function ($scope, User) { $scope.User = User; }]) .factory('User', function(){ return { exists: false, }; })
And this is the contents of the base.index child state template:
<input type="checkbox" ng-model="User.exists" /> <button ng-click="$state.go('base.index', null, {reload: true})" >reload</button>
Check that everything is in effect here
Radim KΓΆhler
source share