javascript - How to not call the directive everytime i reload a page -
i have problem directive,help me solve this. directive changes css style, everytime when go page of these reloads, , not want this.
directive('layoutsettings', function ($http) { return { restrict: 'a', link: function (scope, element, $rootscope) { $rootscope.selectedlayout = {}; $http.get('http://localhost/obp_shop/api/layoutsettings/getvalue').success(function(data) { $rootscope.selectedlayout = data; console.log($rootscope.selectedlayout); $(element).css({ 'background-color': $rootscope.selectedlayout[0].value }); $(element).css({ 'background-image': 'url(data:image/jpeg;base64,' + $rootscope.selectedlayout[1].value + ')' }); $('.btn-primary').css({ 'background-color': $rootscope.selectedlayout[2].value }); $('.btn-default').css({ 'background-color': $rootscope.selectedlayout[2].value }); $('btn-primary').css({ 'color': $rootscope.selectedlayout[3].value }); $('.btn').css({ 'font-size': $rootscope.selectedlayout[4].value }); $('h1,h2,h3,h4,h5,h6').css({ 'color': $rootscope.selectedlayout[5].value }); $('h1,h2,h3,h4,h5,h6').css({ 'font-size': $rootscope.selectedlayout[6].value }); $(element).css({ 'color': $rootscope.selectedlayout[7].value }); $(element).css({ 'font-size': $rootscope.selectedlayout[8].value }); }); } }; });
and directive on body of index page, other pages, because i'm using ui router.
<body class="container" ng-app="routerapp" style="padding-top: 50px;" layout-settings> <div ui-view cg-busy="{promise:promise}"></div> </body>
how can use directive once? thanks.
my issue fixed putting directive in div ui-view.
Comments
Post a Comment