gpt4 book ai didi

angularjs - 如何使用requirejs加载css?

转载 作者:行者123 更新时间:2023-12-02 23:44:06 25 4
gpt4 key购买 nike

这是我的 requirejs 配置文件。我在基于 Angular 的项目中使用 require js 。如果我可以使用 requirejs 加载 css,我也可以组织我的 css 文件!我是 requirejs 概念的新手。任何帮助表示赞赏

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']);
});

这是我的主 Controller

define(function(){

var coreModel = angular.module('coreModel',['test']);

coreModel.controller('mainController',function($scope){
$scope.test = "Hello World";
});
});

如何使用 requirejs 加载 css ?

最佳答案

我宁愿建议您使用 ocLazyLoad 做一些不同的事情。

引用我的回答here

按照上述链接的初始步骤进行配置

我建议您在 Controller 文件中使用这种方式,如下所示

(function () {
angular.module('myApp').controller("homeCtrl", function ($ocLazyLoad,$scope) {

//this line loads your styles and apply it
$ocLazyLoad.load('style.css');

});
})();

<强> LIVE DEMO

注意:在演示中点击菜单->点击主页

关于angularjs - 如何使用requirejs加载css?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42532079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com