gpt4 book ai didi

javascript - 如何在每次重新加载页面时不调用指令

转载 作者:行者123 更新时间:2023-11-28 07:20:54 25 4
gpt4 key购买 nike

我的指令有问题,帮我解决这个问题。这是我更改 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>

如何才能只使用该指令一次?谢谢。

最佳答案

通过将指令放入带有 ui-view 的 div 中,我的问题得到了解决。

关于javascript - 如何在每次重新加载页面时不调用指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32096390/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com