【发布时间】:2014-10-23 11:54:53
【问题描述】:
我从 bootswatch 下载了主题,并试图让用户切换主题。切换主题后,所有引导 css 都会暂时消失,直到加载新主题。如何在加载 css 之前阻止更改,或者在加载新主题之前切换回默认主题?
index.ejs(在头部)
<link rel="stylesheet" href="/external/bootstrap/css/bootstrap_yeti.min.css"
ng-if="myTheme == ''">
<link rel="stylesheet" ng-href="/external/bootstrap/css/bootstrap_{{myTheme}}.min.css"
ng-if="myTheme != ''">
选择
<select class="form-control"
id="theme"
name="theme"
ng-model="theme"
ng-change="newTheme()">
<option value="" disabled>Select Theme</option>
<option ng-repeat="(key, val) in availableThemes" value="{{val}}">{{key}}</option>
</select>
索引控制器
$scope.myTheme = '';
$rootScope.$watch('myTheme', function(value) {
if (value != undefined) {
$scope.myTheme = value;
}
});
选择控制器
$scope.availableThemes = {
Cerulean: 'cerulean',
Cosmo: 'cosmo',
Yeti: 'yeti'
};
$scope.newTheme = function() {
console.log($scope.theme);
if ($scope.theme != undefined) {
$rootScope.myTheme = $scope.theme;
}
}
感谢任何帮助!谢谢
【问题讨论】:
-
尝试使用其中一个异步加载库,如 requirejs 或 dominoes 等,并在其回调中更改 myTheme 变量
标签: javascript html css angularjs twitter-bootstrap