[Angular 2] Controlling how Styles are Shared with View Encapsulation
2016-03-21 19:31
363 查看
Style and View Encapsulation is best understood by seeing how each option (Emulated, Native, and None) compare to each other.
Emulated: default
Native:
None
![](http://images2015.cnblogs.com/blog/364241/201603/364241-20160321192752917-216629351.png)
![](http://images2015.cnblogs.com/blog/364241/201603/364241-20160321192907714-716081724.png)
Emulated: default
(parent style pass )in and no (child style go) out
Native:
no in and no out
None
in and out
import {Component, Input, ViewEncapsulation} from 'angular2/core'; @Component({ selector: 'todo-item-renderer', encapsulation:ViewEncapsulation.Emulated, //Default, (parent style pass )in and no (child style go) out // encapsulation:ViewEncapsulation.Native, // no in and no out //encapsulation:ViewEncapsulation.None, // in and out template: ` <style> .completed{ text-decoration: line-through; } </style> <div> <span [ngClass]="todo.status" [contentEditable]="todo.isEdit">{{todo.title}}</span> <button (click)="todo.toggle()">Toggle</button> <button (click)="todo.edit()">Edit</button> </div> ` }) export class TodoItemRenderer{ @Input() todo }
![](http://images2015.cnblogs.com/blog/364241/201603/364241-20160321192752917-216629351.png)
encapsulation:ViewEncapsulation.Native, // no in and no out
![](http://images2015.cnblogs.com/blog/364241/201603/364241-20160321192907714-716081724.png)
encapsulation:ViewEncapsulation.None, // in and out
![](http://images2015.cnblogs.com/blog/364241/201603/364241-20160321193055136-715647312.png)
相关文章推荐
- [Angular 2]ng-class and Encapsulated Component Style2
- [Angular 2] Passing data to components with @Input
- angularJS provider/factory/service初解析
- 实践中学习AngularJS表单
- 为克服HTML在构建应用上的不足而设计! AngularJS简介!零玖玖教育
- AngularJS UI Router(ui.router)嵌套视图(Nested Views)
- ionic & AngularJS 传递url类型的参数
- Angular报错
- [Angular 2] Adding a data model
- [Angular 2] Using ng-model for two-way binding
- [Angular 2] Using ng-for to repeat template elements
- AngularJS学习笔记之一: AngularJS入门
- AngularJS学习笔记之二:开发、调试和测试工具
- [Angular 2] Using the @Inject decorator
- AngularJS中的指令实践开发指南(二)
- AngularJS 中的指令实践开发指南(一)
- 浅析AngularJS中的指令
- angularjs控制器之间通信,事件通知服务
- AngularJS入门之动画
- angularjs学习3--模块module