如何根据用户单击的按钮切换/切换 AngularJS 页面的样式表?
问问题
4143 次
1 回答
17
您实际上可以在 html 级别放置一个控制器并修改link
标签的 href:
控制器:
var app = angular.module('plunker', []);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
app.controller('headController', function($scope) {
$scope.stylePath = 'style.css'
$scope.changePath = function() {
$scope.stylePath='style2.css';
};
});
标记:
<!doctype html>
<html ng-app="plunker" ng-controller='headController' >
<head >
<meta charset="utf-8">
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="{{stylePath}}">
<script src="http://code.angularjs.org/1.1.4/angular.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
Hello {{name}}!
<button ng-click="changePath()">Change</button>
</body>
</html>
于 2013-05-13T03:20:59.213 回答