angularjs - Angular UI Router Set Scope/Variable -
i have angular app using ui router routing purposes. each time change router, change header of page, , seems $stateprovider easiest way that. have $stateprovider:
$stateprovider .state('index', { url: "/", views: { "rightcontainer": { templateurl: "viewa.html" }, }, controller: function ($scope) { $scope.data.header = "header 1" } }) .state('details', { url: "/details", views: { "rightcontainer": { templateurl: "viewb.html" }, }, controller: function ($scope) { $scope.data.header = "header 2" } });
i want have header:
<div data-ng-controller="mainctrl"> <div class='bg'>{{data.header}}</div> </div>
you can use data https://github.com/angular-ui/ui-router/wiki#attach-custom-data-to-state-objects or other approach
.run(function ($state,$rootscope$filter,windowutils) { $rootscope.$state = $state; $rootscope.$on('$statechangesuccess', function(event, tostate) { var statename = tostate.name; //switch windowutils.settitle(statename); }); }) .factory('windowutils', function($window) { return { settitle:function(title){ var sep = ' - '; var current = $window.document.title.split(sep)[0]; $window.document.title = current + sep + title; } }; })
Comments
Post a Comment