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

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

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

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

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

3.Examples

In Components

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

In Directives

myApp.directive('myDirective', function () {
return {
restrict: 'E',
templateUrl: 'my-directive/my-directive.html',
/* Binding css to directives */
css: 'my-directive/my-directive.css'
}
});

In Controllers

myApp.controller('pageCtrl', function ($scope, $css) {

  // Binds stylesheet(s) to scope create/destroy events (recommended over add/remove)
$css.bind({
href: 'my-page/my-page.css' // 该路径为文件所在路径
}, $scope); // Simply add stylesheet(s)
$css.add('my-page/my-page.css'); // Simply remove stylesheet(s)
$css.remove(['my-page/my-page.css','my-page/my-page2.css']); // Remove all stylesheets
$css.removeAll(); });

For Routes (Angular's ngRoute)

Requires ngRoute as a dependency

myApp.config(function($routeProvider) {

  $routeProvider
.when('/page1', {
templateUrl: 'page1/page1.html',
controller: 'page1Ctrl',
/* Now you can bind css to routes */
css: 'page1/page1.css'
})
.when('/page2', {
templateUrl: 'page2/page2.html',
controller: 'page2Ctrl',
/* You can also enable features like bust cache, persist and preload */
css: {
href: 'page2/page2.css',
bustCache: true
}
})
.when('/page3', {
templateUrl: 'page3/page3.html',
controller: 'page3Ctrl',
/* This is how you can include multiple stylesheets */
css: ['page3/page3.css','page3/page3-2.css']
})
.when('/page4', {
templateUrl: 'page4/page4.html',
controller: 'page4Ctrl',
css: [
{
href: 'page4/page4.css',
persist: true
}, {
href: 'page4/page4.mobile.css',
/* Media Query support via window.matchMedia API
* This will only add the stylesheet if the breakpoint matches */
media: 'screen and (max-width : 768px)'
}, {
href: 'page4/page4.print.css',
media: 'print'
}
]
}); });

相关链接参考:

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. 【kd-tree】bzoj1176 [Balkan2007]Mokia

    裸题不多说,注意在sqrt(n*log(n))次插入后重构树以保持深度. #include<cstdio> #include<cmath> #include<algori ...

  2. 解决ubuntu系统中wireshark:Couldn't run /usr/bin/dumpcap in child process: Permission denied的问题

    ubuntu系统运行WIreshark的时候,出现如下错误: Couldn't run /usr/bin/dumpcap in child process: Permission denied 解决办 ...

  3. 显示字符 Exercise06_12

    /** * @author 冰樱梦 * 时间:2018年下半年 * 题目:显示字符 *1 2 3 4 5 6 7 8 9 : ; < = > ? @ A B C D E F G H I J ...

  4. Bootstrap-table自定义可编辑每页显示记录数

    写在前面: 最近在做的person功能,由于后期系统中person人数较多,不利用查找person,故需求方将要求可以自己编辑每页显示的数目,而不是固定的写死每页显示的数目. 下面先来看下bootsr ...

  5. ListView控件(上)数据适配器:ListView绑定监听是SetOnItemClickListener

    (一) 1.效果图: 2.MainActivity.java package com.example.app5; import android.support.v7.app.AppCompatActi ...

  6. 为ASP.NET WEB API生成人性化说明文档

    一.为什么要生成说明文档 我们大家都知道,自己写的API要供他人调用,就需要用文字的方式将调用方法和注意事项等写成一个文档以更好的展示我们设计时的想法和思路,便于调用者更加高效的使用我们的API. 当 ...

  7. android多线程-AsyncTask之工作原理深入解析(下)

    关联文章: Android 多线程之HandlerThread 完全详解 Android 多线程之IntentService 完全详解 android多线程-AsyncTask之工作原理深入解析(上) ...

  8. 简化调用Web Service

    年前在客户那里做POC,因为成型的OTMCS暴露Web Service的Schema太长,导致ICS无法支持和映射,讨论过后决定对Web Service调用进行封装,因OTMCS WebService ...

  9. OS中处理机调度模型和调度算法

    OS中处理机调度模型和调度算法 调度层次 1.1. 高级调度(长程调度,作业调度) 功能:依据某种算法.把在外存队列上处于后备队列的那些作业调入内存.以作业为操做对象. 作业:比程序更为广泛的概念,不 ...

  10. Java调用Oracle存储过程

    package com.hp.test; import java.sql.CallableStatement; import java.sql.Connection; import java.sql. ...