gpt4 book ai didi

html - AngularJS:使用 ng-repeat 动态加载 CSS 样式表

转载 作者:太空宇宙 更新时间:2023-11-04 14:05:27 25 4
gpt4 key购买 nike

我已将我的样式表拆分为每个包含的单独模块,我想动态加载它们但遇到了一些困难,在呈现时我只获得应加载的每个工作表的以下信息:

<link ng-repeat="inlude in includes" rel="stylesheet" href="" class="ng-scope">

这是我的 HTML:

<!DOCTYPE html>
<html ng-app="forum" ng-controller="masterCtrl">
<head>
<title>Forum</title>
<link rel="stylesheet" href="/stylesheets/reset.css">
<link rel="stylesheet" href="/stylesheets/style.css">
<link ng-repeat="inlude in includes" rel="stylesheet" href="{{include.stylesheet}}">
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.0.8/angular-resource.min.js"></script>
<script src="/scripts/app.js"></script>
<script src="/scripts/controllers.js"></script>
<!--[if lt IE 9]>
<script src="/scripts/html5shiv.js"></script>
<![endif]-->
</head>
<body ng-view>
</body>
</html>

这是我的主 Controller :

function masterCtrl($scope){
$scope.includes = {
header: {
src: 'views/includes/header.html',
stylesheet: 'stylesheets/header.css',
searchQuery: ''
},
threadList: {
src: 'views/includes/threadList.html',
stylesheet: 'stylesheets/threadList.css'
}
};
}

其他一切正常,感谢观看。

最佳答案

在将 href 更改为 ng-href 的基础上,修改如下所示的链接,因为您没有为样式表设置源。

<link ng-repeat="include in includes" rel="stylesheet" ng-href="include.stylesheet" class="ng-scope">

附言它没有工作,因为您在 include 中输入错误 — inlude in includes

关于html - AngularJS:使用 ng-repeat 动态加载 CSS 样式表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21165025/

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