1. style.propertyName

[style.Css属性名] = 'Css属性值变量'/"'css属性值'"

// app.component.ts
export class AppComponent {
fontSize = '32px';
} // app.component.html
<div [style.fontSize]="fontSize" [style.color]="'red'">styleBinding</div>

效果:

2. ngStyle

[ngStyle]="{'css属性名': 'css属性值'}"

[ngStyle]="{'css属性名': 判断语句 ?'判断语句为true时的css属性值' : '判断语句为false时的css属性值'}"

// app.component.ts
export class AppComponent {
isMax = false;
} // app.component.html
//Css属性值-固定值
<div [ngStyle]="{'color': 'red'}">ngStyle</div>
//Css属性值-通过判断取值
<div [ngStyle]="{'font-size': isMax ? '24px' : '12px'}">ngStyle-添加判断</div>

效果:

3. ngClass

[ngClass]="{'需要添加的类名': 判断语句}";;;当条件为ture时,添加类;为false时,不添加该类

// app.component.ts
export class AppComponent {
isActive = true;
isFocus = true;
} // app.component.html
// 一个类通过判断添加
<div [ngClass]="{'active': isActive}">ngClass</div>
// 多个类通过判断添加时,用逗号隔开
<div [ngClass]="{'active': isActive, 'primary': isFocus}">ngClass</div> // app.component.css
.active { background: #d0d0d0;}
.primary { color: #198fff; }

效果:

Angular 样式绑定的更多相关文章

  1. angularJS 状态样式绑定

    angularJS提供输入框不同状态下的样式绑定 输入框有4种状态 ng-model 指令可以为应用数据提供状态值(invalid, dirty, touched, error): <!DOCT ...

  2. Vue 样式绑定 && 条件渲染

    1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8" /> 5 & ...

  3. wpf样式绑定 行为绑定 事件关联 路由事件实例

    代码说明:我要实现一个这样的功能  有三个window窗口  每个窗体有一个label标签  当我修改三个label标签中任意一个字体颜色的时候  其他的label标签字体颜色也变化 首先三个窗体不用 ...

  4. 3-5 Vue中的样式绑定

    Vue中的样式绑定: 本案例,简单设计一个<div>的点击绑定事件来改变div的样式效果 方法一:[class] ①(class和对象的绑定) //如上,运用class和一个对象的形式来解 ...

  5. Vue(九):样式绑定v-bind示例

    Vue.js class class 与 style 是 HTML 元素的属性,用于设置元素的样式,我们可以用 v-bind 来设置样式属性. Vue.js v-bind 在处理 class 和 st ...

  6. vue的样式绑定

    vue在样式绑定,看这官方的文档,怎么试都不行后来看了一篇文章 <div :class="[rankClass]"></div> <script> ...

  7. Vue.js:样式绑定

    ylbtech-Vue.js:样式绑定 1.返回顶部 1. Vue.js 样式绑定 Vue.js class class 与 style 是 HTML 元素的属性,用于设置元素的样式,我们可以用 v- ...

  8. Vue.js学习笔记 第二篇 样式绑定

    Class绑定的对象语法 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> ...

  9. Vue 将样式绑定到一个对象让模板更清晰

    Vue 将样式绑定到一个对象让模板更清晰 <div id="app"> <div v-bind:style="styleObject"> ...

随机推荐

  1. javaScript 基础知识汇总(六)

    1.基本类型与对象的区别 基本类型:是原始类型的中的一种值. 在JavaScript中有6中基本类型:string number  boolean  symbol  null  undefined 对 ...

  2. win8调出右侧菜单栏

    1.快捷键:win+c 2.鼠标放在右下角1s

  3. I-Just Jump_2019牛客暑期多校训练营(第八场)

    题目链接 Just Jump 题意 有L+1个点,初始在第0个点上,要跳到第L个点,每次至少跳d格,也就是在点x至少要跳到x+d,且有m个限制 \((t_i, p_i)\)指跳第\(t_i\)次不能跳 ...

  4. gym/101873/GCPC2017

    题目链接:https://codeforces.com/gym/101873 C. Joyride 记忆化搜索形式的dp #include <algorithm> #include < ...

  5. CodeForces 590C Three States BFS

    Three Statesy 题解: 以3个大陆为起点,都dfs一遍,求出该大陆到其他点的最小距离是多少, 然后枚举每个点作为3个大陆的路径交点. 代码: #include<bits/stdc++ ...

  6. 详解RMQ-ST算法 ST模板

    RMQ问题是求解区间最值的问题. 这里分析的是ST算法,它可以对所有要处理的数据做到O(nlogn)的预处理,对每个区间查询做到O(1)查询 ST算法本质是一个DP的过程 这里通过举一个求最大值实例来 ...

  7. Different Integers 牛客网暑期ACM多校训练营(第一场) J 离线+线状数组或者主席树

    Given a sequence of integers a1, a2, ..., an and q pairs of integers (l 1, r1), (l2, r2), ..., (lq, ...

  8. Robot Framework自动化测试

    http://blog.csdn.net/wangjingna/article/details/49782001

  9. Spring 两大核心 IOC 和 AOP

    如果你的简历上写着Spring (请详述一下spring的两大核心)这个问题一定会被问到. 一.什么叫IOC 1. IOC 全称(Inversion of Control)-- 控制反转. IOC 只 ...

  10. Protobuf 安装及 Python、C# 示例

    01| 简介02| 安装2.1 Windows 下安装03| 简单使用3.1 编译3.2 Python 示例3.3 C# 示例 01| 简介 Protobuf(Protocol Buffers),是 ...