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");
}
}
});
欢迎加入,Java,前端的共同学习【爱问共享编程部落】 479668591