1) Include the required JavaScript libraries in your index.html (ngRoute and UI Router are optional).  引入

  1. <script src="/libs/angularjs/1.5.6/angular.min.js"></script>
  2. <script src="/libs/angularjs/1.5.6/angular-routes.min.js"></script>
  3. <script src="/libs/angular-css/angular-css.min.js"></script>
  1.  

You can download AngularCSS from GitHub. Also available via Bower and CDN.

2. Add angularCSS as a dependency for your app.    配置

  1. var myApp = angular.module('myApp', ['ngRoute','angularCSS']);

3.Examples

In Components

  1. myApp.component('myComponent', {
  2. css: 'my-component/my-component.css' // <--- magic!
  3. templateUrl: 'my-component/my-component.html',
  4. });

In Directives

  1. myApp.directive('myDirective', function () {
  2. return {
  3. restrict: 'E',
  4. templateUrl: 'my-directive/my-directive.html',
  5. /* Binding css to directives */
  6. css: 'my-directive/my-directive.css'
  7. }
  8. });

In Controllers

  1. myApp.controller('pageCtrl', function ($scope, $css) {
  2.  
  3. // Binds stylesheet(s) to scope create/destroy events (recommended over add/remove)
  4. $css.bind({
  5. href: 'my-page/my-page.css' // 该路径为文件所在路径
  6. }, $scope);
  7.  
  8. // Simply add stylesheet(s)
  9. $css.add('my-page/my-page.css');
  10.  
  11. // Simply remove stylesheet(s)
  12. $css.remove(['my-page/my-page.css','my-page/my-page2.css']);
  13.  
  14. // Remove all stylesheets
  15. $css.removeAll();
  16.  
  17. });

For Routes (Angular's ngRoute)

Requires ngRoute as a dependency

  1. myApp.config(function($routeProvider) {
  2.  
  3. $routeProvider
  4. .when('/page1', {
  5. templateUrl: 'page1/page1.html',
  6. controller: 'page1Ctrl',
  7. /* Now you can bind css to routes */
  8. css: 'page1/page1.css'
  9. })
  10. .when('/page2', {
  11. templateUrl: 'page2/page2.html',
  12. controller: 'page2Ctrl',
  13. /* You can also enable features like bust cache, persist and preload */
  14. css: {
  15. href: 'page2/page2.css',
  16. bustCache: true
  17. }
  18. })
  19. .when('/page3', {
  20. templateUrl: 'page3/page3.html',
  21. controller: 'page3Ctrl',
  22. /* This is how you can include multiple stylesheets */
  23. css: ['page3/page3.css','page3/page3-2.css']
  24. })
  25. .when('/page4', {
  26. templateUrl: 'page4/page4.html',
  27. controller: 'page4Ctrl',
  28. css: [
  29. {
  30. href: 'page4/page4.css',
  31. persist: true
  32. }, {
  33. href: 'page4/page4.mobile.css',
  34. /* Media Query support via window.matchMedia API
  35. * This will only add the stylesheet if the breakpoint matches */
  36. media: 'screen and (max-width : 768px)'
  37. }, {
  38. href: 'page4/page4.print.css',
  39. media: 'print'
  40. }
  41. ]
  42. });
  43.  
  44. });
  1.  

相关链接参考:

https://github.com/castillo-io/angular-css(github源码)

http://door3.com/insights/introducing-angularcss-css-demand-angularjs#.V-CKT5FJIdZ(Introducing AngularCSS: CSS On-Demand for AngularJS)

http://www.ituring.com.cn/tupubarticle/1385(第 11 章 AngularJS模块加载)

AngularCSS 的引入: CSS On-Demand for AngularJS的更多相关文章

  1. CSS系列:在HTML中引入CSS的方法

    HTML与CSS是两个作用不同的语言,它们同时对一个网页产生作用,因此必须将CSS与HTML链接在一起使用.在HTML中,引入CSS的方法主要有4种:行内式.内嵌式.导入式和链接式. 1. 行内式 行 ...

  2. Spring MVC:在jsp中引入css

    为了将css引入jsp中,今天可真是踩了好多坑,最后在stackoverflow上找到了解决方法,不多说贴出代码. 在web.xml中添加以下代码: <servlet-mapping> & ...

  3. html引入css文件

    在HTML中,引入CSS的方法主要有行内式.内嵌式.导入式和链接式. 行内式:即在标记的style属性中设定CSS样式,这种方式本质上没有体现出CSS的优势,因此不推荐使用.例: <html&g ...

  4. 引入CSS

    前面的话 Web早期,HTML是一种很有限的语言,这种语言不关心外观,它只是一种简洁的小型标记机制.随着Mosaic网页浏览器的出现,网站开始到处涌现.对于页面改变外观的需求增加,于是增加了类似< ...

  5. jquery,js引入css文件,js引入头尾

    jquery,js引入css文件,js引入头尾 今天在项目中,需要把20多个页面加上头和尾部,头和尾是我写的,所以小师傅把这个工作交给我了. 我开始往里面加,先引入common.css,在body开始 ...

  6. 引入css外部样式表

    前言 为什么会有这篇文章,外部引入样式有什么好谈的,不外乎就是 <link rel="stylesheet" href="style.css" /> ...

  7. 引入css ,使用@import和link的方式

    我们也经常听到有人说要使用link来引入CSS更好,但是你知道为什么吗? 继续往下看 linklink就是把外部CSS与网页连接起来. @importimport文字上与link的区别就是它可以把在一 ...

  8. 引入CSS文件的方式,以及link与@import的区别

    一.引入css的方式 在HTML中引入css的方法主要有4种:行内式.内嵌式.链接式和导入式. 1.行内式 <div style="background:yellow;"&g ...

  9. vue脚手架使用swiper /引入js文件/引入css文件

    1.安装vue-cli 参考地址:https://github.com/vuejs/vue-cli 如果不使用严格语法需要在后三项打no:(加了挺头疼的,老是报错,但是对自己的代码规范性也是有很大的帮 ...

  10. HTML中引入CSS的方法

    在HTML中引入CSS的方法主要有四种,它们分别是行内式.内嵌式.链接式和导入式. 1.行内式 行内式是在标记的style属性中设定CSS样式.这种方式没有体现出CSS的优势,不推荐使用. 2.内嵌式 ...

随机推荐

  1. 【博弈论】【SG函数】bzoj1457 棋盘游戏

    一开始就必胜的特判一下. #include<cstdio> #include<cstring> #include<set> #include<algorith ...

  2. 【kmp算法】模板

    void GetFail(char P[],int __next[])//__next[i]表示s[0]~s[i-1]的前缀中,最大长度相等的前后缀是多少 { __next[0]=-1; int le ...

  3. 【贪心】【二维偏序】【权值分块】bzoj1691 [Usaco2007 Dec]挑剔的美食家

    既然题目中的要求满足二维偏序,那么我们很自然地想到将所有东西(草和牛)都读进来之后,对一维(美味度)排序,然后在另一维(价值)中取当前最小的. 于是,Splay.mutiset.权值分块什么的都支持查 ...

  4. JavaScript的=、==和===

    (1) 百度知道上的解释: = 为对象赋值 == 表示两个对象toString值相等 === 表示两个对象类型相同且值相等 (2)  知乎上的解释: 绝大多数场合应该使用 === ,只有检测 null ...

  5. windbg --sqlserver 实例 转

    http://blog.csdn.net/obuntu/article/details/5962378 SQLSERVER DUMP 调试 在下面的对话框输入 ~ 会出现线程的信息 0:000> ...

  6. TELNET终端类型选项

    转:http://www.cnpaf.net/Class/Telnet/200408/5.html 1. 命令名称及编号TERMINAL-TYPE242.命令含义IACWILLTERMINAL-TYP ...

  7. oracle审计AUD$过大导致的数据库登录异常

      今天,省分技术人员反映数据库登录异常. 查询oerr,发现该错误是一般性提示,可能导致的原因有数据库未注册.本地文件配置问题等.由于平时连接并没有问题,是突发情况,所以排除了配置问题. 远程登录查 ...

  8. ASP.NET MVC DropdownList的使用

    1:直接使用HTML代码写 <select name="year"> <option value="2011">2010</opt ...

  9. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:3.安装Oracle RAC-3.1.安装并配置ASM驱动

    3.1.安装并配置ASM驱动 3.3.1.检查内核 [root@linuxrac2 etc]# uname -r 2.6.18-164.el5 下载以下rpm包(注意rpm包版本和Linux内核版本一 ...

  10. Linux的PCI驱动分析

    1. 关键数据结构 PCI设备上有三种地址空间:PCI的I/O空间.PCI的存储空间和PCI的配置空间.CPU可以访问PCI设备上的所有地址空间,其中I/O空间和存储空间提供给设备驱动程序使用,而配置 ...