2015-08-19 32 views
0

我遇到了指令問題,請幫我解決此問題。 這是我的指令,它改變了CSS樣式,但每當我到另一個頁面時,所有這些重新加載,我不想這樣。如何在每次重新加載頁面時不要調用該指令

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 }); 
        }); 
       } 
     }; 
    }); 

而這個指令是在索引頁的主體上,我得到其他頁面,因爲我使用的是ui路由器。

<body class="container" ng-app="routerApp" style="padding-top: 50px;" layout-settings> 
<div ui-view cg-busy="{promise:promise}"></div> 
</body> 

我該如何使用這個指令只有一次? 謝謝。

回答

0

我的問題是通過將指令放入div中的ui-view來解決的。

相關問題