如何使用requirejs加载CSS? [英] How to load css by using requirejs?
问题描述
这是我的requirejs配置文件.我在基于角度的项目上使用require js.如果我可以用 requirejs
加载CSS,那么我也可以组织CSS文件!我是 requirejs
概念的新手.任何帮助表示赞赏
This is my requirejs config file. I'm using require js on my angular based project. If I could load css with requirejs
I would be able to organize my css files too! I'm new to requirejs
concept. Any help appreciated
require.config({
paths:{
'angular' : "agular",
'app' : 'app',
'coreModel' : 'coreModel',
'test' : 'controller/test'
},
shim: {
'app' : {
deps :['angular','coreModel',]
},
'coreModel' : {
deps : ['angular','test']
},
'test' : {
deps : ['angular',]
}
},
});
require(['app',],function(){
angular.bootstrap(document,['app']);
});
这是我的主控制器
define(function(){
var coreModel = angular.module('coreModel',['test']);
coreModel.controller('mainController',function($scope){
$scope.test = "Hello World";
});
});
如何使用requirejs加载CSS?
How can I load css with requirejs ?
推荐答案
我宁愿建议您使用ocLazyLoad进行其他操作.
I would rather suggest you to something different using a ocLazyLoad.
参考我的答案 这里
Reference to my answer here
按照上述链接的初始步骤进行配置
Follow the initial steps of the above link for configuration
我建议您在以下Controller文件中使用这种方式
I would suggest you to use this way in your Controller file as below
(function () {
angular.module('myApp').controller("homeCtrl", function ($ocLazyLoad,$scope) {
//this line loads your styles and apply it
$ocLazyLoad.load('style.css');
});
})();
LIVE DEMO
注意:在演示中,单击菜单->单击主页
Note: In the demo click on the menu- > click home
这篇关于如何使用requirejs加载CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!