angular中几种加载css的方法
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的方法的更多相关文章
- angular中按需加载js
按需加载估计是大家在使用angular之后最想解决的问题吧,因为angular的依赖机制,导致了必须在第一次加载的时候就加载所有js文件,小项目还好,稍大一点的项目如果有上百个js文件,不管是从效率还 ...
- buttongroup中content一次性加载的解决方法
buttongroup一次性加载所有内容的解决方法 如下图所示: 第一步: 设置windowcontainer的autoLoad属性为false(默认情况下autoLoad属性为true,所以会加载所 ...
- Java的几种加载驱动的方法
1.Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); 2.DriverManager.registerD ...
- 加载 CSS 时不影响页面渲染
转自:http://www.oschina.net/translate/loading-css-without-blocking-render 本文展示了一种技术,它能通过异步下载样式表,以阻止它们的 ...
- yii2 如何在页面底部加载css和js
作者:白狼 出处:www.manks.top/article/yii2_load_js_css_in_end 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接 ...
- Python 中 unittest 框架加载测试用例的常用方法
unittest 当中为我们提供了许多加载用例的方法,这里说下常用的两种方法...推荐使用第二种 第一种加载测试用例的方法:使用加载器加载两个模块 需要把所有的模块加载到套件中 那么就可以自动的运行所 ...
- jQuery中的ready方法及实现按需加载css,js
模拟jQuery中的ready方法及实现按需加载css,js 一.ready函数的实现 经常用jQuery类库或其他类库中的ready方法,有时候想想它们到底是怎么实现的,但是看了一下jQuery中的 ...
- Webpack 2 视频教程 011 - Webpack2 中加载 CSS 的相关配置与实战
原文发表于我的技术博客 这是我免费发布的高质量超清「Webpack 2 视频教程」. Webpack 作为目前前端开发必备的框架,Webpack 发布了 2.0 版本,此视频就是基于 2.0 的版本讲 ...
- android中的LaunchMode详解----四种加载模式
Activity有四种加载模式: standard singleTop singleTask singleInstance 配置加载模式的位置在AndroidManifest.xml文件中activi ...
随机推荐
- 【aspnetcore】在过滤器(Filter)中使用注入服务(ServiceFilter|TypeFilter)
在MVC中,AOP是很常用的功能,我们经常会使用如 ActionFilter,IAuthorizeFilter 等描述对Controller和Action进行约束和扩展,一般做法如下: public ...
- 25 Groovy 相关资料
Groovy Homepage Groovy API page Groovy documentation Groovy Goodness blog series from Hubert Klein I ...
- HTML的基础结构
<html>内容</html> 解释:HTML文档的文档标记,也称为HTML开始标记 功能:这对标记分别位于网页的最前端和最后端 <head>内容</head ...
- L. Right Build bfs
http://codeforces.com/gym/101149/problem/L 给出一个有向图,从0开始,<u, v>表示要学会v,必须掌握u,现在要学会a和b,最小需要经过多少个点 ...
- 关于nodejs模块安装后找不到包解决办法
主要原因是类似bower.gulp这些包后,没有添加到环境变量,但是有洁癖的我也不希望添加太多的软链接,所以在用phpstorm开始时有需要的情况下 定义临时的环境变量 http://stackove ...
- Django中对单表的增删改查
之前的简单预习,重点在后面 方式一: # create方法的返回值book_obj就是插入book表中的python葵花宝典这本书籍纪录对象 book_obj=Book.objects.creat ...
- 使用Android-Debug-Database 在浏览器中查看App的数据库
使用参考:http://www.jianshu.com/p/89ccae3e590b源码地址:https://github.com/amitshekhariitbhu/Android-Debug-Da ...
- 关于svn提交的时候强制写注释
本文固定链接: http://www.linuxyan.com/linux-service/229.html 转载请注明: admin 2012年09月29日 于 ㄨ销声匿迹.Linux 发表 在sv ...
- Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法
Selenium私房菜系列10 -- 我遇到的问题及解决问题的方法
- 异步 ThreadPool
线程池是单例,一个进程里只有一个线程池 private void btnThreadPool_Click(object sender, EventArgs e) { Stopwatch watch = ...