1.Style URLs in Metadata

We can load styles from external CSS files by adding a styleUrls attribute into a component's @Component decorator:

@Component({
selector: 'hero-details',
template: `
<h2>{{hero.name}}</h2>
<hero-team [hero]=hero></hero-team>
<ng-content></ng-content>
`,
styleUrls: ['app/hero-details.component.css']
})
export class HeroDetailsComponent {
/* . . . */
}

  

2.Users of module bundlers like Webpack may also use the styles attribute to load styles from external files at build time. They could write:

styles: [require('my.component.css')]

We set the styles property, not styleUrls property! The module bundler is loading the CSS strings, not Angular. Angular only sees the CSS strings after the bundler loads them. To Angular it is as if we wrote the styles array by hand. Refer to the module bundler's documentation for information on loading CSS in this manner.

3.Template Link Tags

We can also embed <link> tags into the component's HTML template.

As with styleUrls, the link tag's href URL is relative to the application root, not relative to the component file.

@Component({
selector: 'hero-team',
template: `
<link rel="stylesheet" href="app/hero-team.component.css">
<h3>Team</h3>
<ul>
<li *ngFor="let member of hero.team">
{{member}}
</li>
</ul>`
})

  

4.CSS @imports

We can also import CSS files into our CSS files by using the standard CSS @import rule.

In this case the URL is relative to the CSS file into which we are importing.

src/app/hero-details.component.css (excerpt):

@import 'hero-details-box.css';

  

angular中几种加载css的方法的更多相关文章

  1. angular中按需加载js

    按需加载估计是大家在使用angular之后最想解决的问题吧,因为angular的依赖机制,导致了必须在第一次加载的时候就加载所有js文件,小项目还好,稍大一点的项目如果有上百个js文件,不管是从效率还 ...

  2. buttongroup中content一次性加载的解决方法

    buttongroup一次性加载所有内容的解决方法 如下图所示: 第一步: 设置windowcontainer的autoLoad属性为false(默认情况下autoLoad属性为true,所以会加载所 ...

  3. Java的几种加载驱动的方法

    1.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 2.DriverManager.registerD ...

  4. 加载 CSS 时不影响页面渲染

    转自:http://www.oschina.net/translate/loading-css-without-blocking-render 本文展示了一种技术,它能通过异步下载样式表,以阻止它们的 ...

  5. yii2 如何在页面底部加载css和js

    作者:白狼 出处:www.manks.top/article/yii2_load_js_css_in_end 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接 ...

  6. Python 中 unittest 框架加载测试用例的常用方法

    unittest 当中为我们提供了许多加载用例的方法,这里说下常用的两种方法...推荐使用第二种 第一种加载测试用例的方法:使用加载器加载两个模块 需要把所有的模块加载到套件中 那么就可以自动的运行所 ...

  7. jQuery中的ready方法及实现按需加载css,js

    模拟jQuery中的ready方法及实现按需加载css,js 一.ready函数的实现 经常用jQuery类库或其他类库中的ready方法,有时候想想它们到底是怎么实现的,但是看了一下jQuery中的 ...

  8. Webpack 2 视频教程 011 - Webpack2 中加载 CSS 的相关配置与实战

    原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...

  9. android中的LaunchMode详解----四种加载模式

    Activity有四种加载模式: standard singleTop singleTask singleInstance 配置加载模式的位置在AndroidManifest.xml文件中activi ...

随机推荐

  1. IIS7文件无法下载问题处理

    使用IIS建立了静态站点,内部放置了一些文件供内部局域网下载使用,但deb等文件格式无法下载. 解决办法: 1.在IIS管理器中点击站点,选择右侧的MIME类型. 2.在MIME类型中添加需要下载文件 ...

  2. idea获取激活码

    访问地址拿到激活码:http://idea.lanyus.com/getkey

  3. CentOS7.2 安装iptables

    1  先检查是否安装了iptables: service iptables status iptables  -L ls /etc/sysconfig/ 综上:命令报错,且 iptables不存在,那 ...

  4. nodejs下express+ejs环境搭建

    nodejs下express+ejs环境搭建   分类: Nodejs 1.进入需要创建项目的目录    cd F:\nodeCode     2.创建一个带ejs模板工程,工程名为haha    e ...

  5. body和普通div背景图宽高百分比的区别

    body和普通div背景图的区别  background: url(//m.360buyimg.com/mobilecms/s220x220_jfs/t2746/167/831241799/29915 ...

  6. 【转】Create Hello-JNI with Android Studio

    [转]Create Hello-JNI with Android Studio From:https://codelabs.developers.google.com/codelabs/android ...

  7. Android属性系统简介

    1.简介 在android 系统中,为统一管理系统的属性,设计了一个统一的属性系统.每个属性都有一个名称和值,他们都是字符串格式.属性被大量使用在Android系统中,用来记录系统设置或进程之间的信息 ...

  8. 【NumPy学习指南】day4 多维数组的切片和索引

    ndarray支持在多维数组上的切片操作.为了方便起见,我们可以用一个省略号(...)来 表示遍历剩下的维度. (1) 举例来说,我们先用arange函数创建一个数组并改变其维度,使之变成一个三维数组 ...

  9. 在Eclipse上运行Spark(Standalone,Yarn-Client)

    欢迎转载,且请注明出处,在文章页面明显位置给出原文连接. 原文链接:http://www.cnblogs.com/zdfjf/p/5175566.html 我们知道有eclipse的Hadoop插件, ...

  10. Node.js 打造实时多人游戏框架

    在 Node.js 如火如荼发展的今天,我们已经可以用它来做各种各样的事情.前段时间UP主参加了极客松活动,在这次活动中我们意在做出一款让“低头族”能够更多交流的游戏,核心功能便是 Lan Party ...