首页 > Web开发 > 详细

angualrjs 自定义css异步加载指令

时间:2017-01-14 12:25:06      阅读:226      评论:0      收藏:0      [点我收藏+]

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");
        }  
    }
});

 

angualrjs 自定义css异步加载指令

原文:http://www.cnblogs.com/guxingzhe/p/6284885.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!