Many Components require different styles based on a set of conditions. Angular 2 helps you style your Components by allows you to define Styles inline, then choosing which styles to use based on the current values in your Controller.

import {Component, Input} from 'angular2/core';
@Component({
selector: 'todo-item-renderer',
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
}

[Angular 2]ng-class and Encapsulated Component Style2的更多相关文章

  1. Angular CLI ng常用指令整理

    一.组件创建 ng generate component heroes 二.运行项目 ng serve --open //--open 立即打开 三.创建指令 ng g directive my-ne ...

  2. [Angular 2] ng-class and Encapsulated Component Styles

    import {Input, Component, View, NgClass} from "angular2/angular2"; @Component({ selector: ...

  3. Angular: 执行ng lint后如何快速修改错误

    当我第一次被分配到“修正执行ng lint语句后的错误”这项任务前,我就被导师提前告知这是一个很无聊的任务,当我开始后,我发现其实有一些办法可以加快这个无聊单调的工作.接下来,我就分享一下我的经验. ...

  4. 从flask视角理解angular(二)Blueprint VS Component

    Component类似flask app下面的每个blueprint. import 'rxjs/add/operator/switchMap'; import { Component, OnInit ...

  5. [Angular 2] Generate and Render Angular 2 Template Elements in a Component

    Angular 2 Components have templates, but you can also create templates inside of your templates usin ...

  6. [Angular 2] Building a Toggle Button Component

    This lesson shows you how to build a Toggle Button in Angular 2 from scratch. It covers using transc ...

  7. ANGULAR 使用 ng build --prod 编译报内存错误的解决办法

    如果你遇到如下的情况 <--- Last few GCs ---> [13724:0000020D39C660D0] 231298 ms: Mark-sweep 1356.3 (1433. ...

  8. [Angular & Unit Testing] Testing a RouterOutlet component

    The way to test router componet needs a little bit setup, first we need to create a "router-stu ...

  9. [Angular Unit Testing] Debug unit testing -- component rendering

    If sometime you want to log out the comonent html to see whether the html render correctly, you can ...

随机推荐

  1. mysql慢查优化总结

    1.优化sql语句结构 or改成union,使用start,limit 先只查询出所有的id,然后再排序.如果查询出所有的id仍然很慢,就要仔细考虑了. 2.添加索引 mysql每次查询只能使用一个索 ...

  2. ajax提交请求为啥url要用这个函数encodeURI

    参考如下: 如果你是通过form提交的,那就不需要用这个了.但是如果是你使用url的方式例如:ajax提交到后台的,就需要对url进行encodeURI编码,否则,会导致后台出现各种乱码,不加enco ...

  3. 查询oracle表和sql数据量大小

    select t.TABLE_NAME,t.NUM_ROWS from user_tables t order by t.TABLE_NAME:--oracle  SELECT object_name ...

  4. vs2013+sql server2012

    学习 vs2013 sql server2012使用 : linp lambda entity framework wcf tfs;

  5. Javascript 常用函数【2】

    1.常规函数javascript常规函数包括以下9个函数:(1)alert函数:显示一个警告对话框,包括一个OK按钮.(2)confirm函数:显示一个确认对话框,包括OK.Cancel按钮.(3)e ...

  6. idea intellij 快捷键(ubuntu版本)

    S + C + T 创建测试类 A + F12 开启终端 C + F12 查看类中的方法属性 ----随时更新,记录快捷方式

  7. Ubuntu最小化桌面快捷键Super+D不生效解决

    之前用的Debian,最近研发老大让统一使用Ubuntu来开发,安装了Ubuntu 15.10之后,设置了最小化桌面的快捷键为Super+D(在Systm Settings/系统设置—>Keyb ...

  8. 安装SQL Server 那些事儿

    SQL版本: Microsoft SQL Server2008 R2 RTM - Express with Advanced Services 错误描述: System.Configuration.C ...

  9. 使用 HTTP 缓存机制提升系统性能

    摘要 HTTP缓存机制定义在HTTP协议标准中,被现代浏览器广泛支持,同时也是一个用于提升基于Web的系统性能的广泛使用的工具.本文讨论如何使用HTTP缓存机制提升基于Web的系统,以及如何避免误用. ...

  10. 文成小盆友python-num17 - django基础

    一.首先了解web应用的本质 对于所有的Web应用,本质上其实就是一个socket服务端,用户的浏览器其实就是一个socket客户端. 下面利用socket实现一个简单的web框架: #!/usr/b ...