html中调用:
<!-- 异步加载css文件 --> <load-css href="css/demo.css"></load-css>
js代码:
/**
* 将对应路径的css插入html页面中
*/
app.directive(‘loadCss‘, function() {
return {
require: ‘?ngModel‘,
restrict: ‘E‘,
link: function ($scope, element, attrs, ngModel) {
$("<link />")
.prop("href", attrs.href)
.prop("type", "text/css")
.prop("rel", "stylesheet")
.appendTo("head");
}
}
});
原文:http://www.cnblogs.com/guxingzhe/p/6284885.html