[ngclass]

  动态改变一个元素的class

  ts:    

    public classcolor:boolean=false;
    public list:any = [{title:"新闻1"},{title:"新闻2"},{title:"新闻3"}]

  html:

    <div>
      <P>动态改变一个元素的class</P>
      <P [ngClass]="{'origin': classcolor,'red': !classcolor}">内容</P>
    </div>
    <div>
      <p>循环数组,数组第一个元素为red</p>
      <ul>
        <li *ngFor="let item of list; let key = index "
        [ngClass]="{'red': key==1,'origin':key==0,'blue':key==2}">{{key}}--{{item.title}}</li>
        <!-- 绑定动态样式的时候,key的值不需要用引号''包裹起来,包裹起来就是一个字符串了,显示的时候就是无状态 -->
      </ul>
    </div>

ts中

  public arrt:any="blue";
  public today:Date= new Date();
  
html中
  <div>
    <p>动态绑定样式[ngstyle]</p>
    <ul>
      <li [ngStyle]="{'color': arrt}">内容</li>
    </ul>
  </div>
  <div>
    <ul>
      <p>管道</p>
      <li>{{today}}</li>
      <!--通过管道,指定格式-->
      <li>{{today | date:'yyyy-MM-dd HH-mm-ss'}}</li>
    </ul>
  </div>
 
 
 
 
 
 
 
 
 

[ngclass]、[ngstyle]、管道的更多相关文章

  1. ng-class ng-style

    https://docs.angularjs.org/api/ng/directive/ngClass 翻译 表达式生成一个空格饭分隔的class字符串 一个对象,它的每一个key在其值为true的时 ...

  2. 关于ng-class,ng-style的用法

    ng-class的使用几种方式 (1):利用双向数据绑定(className根据chang2的值去匹配类) <div class="{{className}}">... ...

  3. Angular 4.x NgClass ngStyle 指令用法

    <some-element [ngClass]="'first second'">...</some-element> <some-element [ ...

  4. angular [NgClass] [NgStyle],NgIf,[ngSwitch][ngSwitchCase]

    [NgClass]  CSS 类会根据表达式求值结果进行更新,更新逻辑取决于结果的类型: string - 会把列在字符串中的 CSS 类(空格分隔)添加进来, Array - 会把数组中的各个元素作 ...

  5. Angular6 学习笔记——组件详解之模板语法

    angular6.x系列的学习笔记记录,仍在不断完善中,学习地址: https://www.angular.cn/guide/template-syntax http://www.ngfans.net ...

  6. Angular 2 技能图谱skill-map

    # Angular 2 技能图谱 ## 模块 ### 自定义模块 - 根模块 - 特性模块 - 共享模块 - 核心模块 ### 内置模块 - ApplicationModule 模块 - Common ...

  7. [Ng]Angular应用点概览

      1. 使用模块化写法. var app = angular.module('myApp', []); app.controller('TextController', function($scop ...

  8. angularJS内置指令一览

    基础ng指令 ng-href ng-src ng-disabled ng-readonly ng-checked ng-selected ng-class ng-style ng-show ng-hi ...

  9. 秒味课堂Angular js笔记------指令

    1.属性指令 angularjs样式相关指令: ng-class ng-style ng-href ng-src ng-attr-(suffix) ng-bind ng-cloak  没解析完之前标签 ...

  10. AngularJS初步

    AngularJS特点 遵循AMD规范 不需要操作节点 对于jquery,一般是利用现有完整的DOM,然后在这戏Dom的基础上进行二次调教了:而对于AngularJS等框架则是根据数据模型以及其对应用 ...

随机推荐

  1. P2766 最长不下降子序列问题 网络流

    link:https://www.luogu.org/problemnew/show/P2766 题意 给定正整数序列x1,...,xn . (1)计算其最长不下降子序列的长度s. (2)计算从给定的 ...

  2. codeforces 811 E. Vladik and Entertaining Flags(线段树+并查集)

    题目链接:http://codeforces.com/contest/811/problem/E 题意:给定一个行数为10 列数10w的矩阵,每个方块是一个整数, 给定l和r 求范围内的联通块数量 所 ...

  3. Caused by: com.fasterxml.jackson.databind.exc.InvalidDefinitionException: No serializer found for class org.apache.catalina.connector.CoyoteWriter and no properties discovered to create BeanSerializer

    一.什么是序列化In computer science, in the context of data storage, serialization is the process of transla ...

  4. Spring MVC 配置类 WebMvcConfigurerAdapter

    WebMvcConfigurerAdapter配置类是spring提供的一种配置方式,采用JavaBean的方式替代传统的基于xml的配置来对spring框架进行自定义的配置.因此,在spring b ...

  5. Spring boot出现Cannot determine embedded database driver class for database type NONE

    在spring boot项目中,我们在pom.xml文件中添加了mysql和mybatis的依赖,我们常常遇到下面这样的问题: Description: Cannot determine embedd ...

  6. linux安装python串口工具pyserial遇到不能成功导入的问题

    常规方法:pip install pyserial导入serial后提示: 解决方法:apt install python3-serial 参考:https://stackoverflow.com/q ...

  7. FreeSql (二十二)Dto 映射查询

    适合喜欢使用 dto 的朋友,很多时候 entity 与 dto 属性名相同,属性数据又不完全一致. 有的人先查回所有字段数据,再使用 AutoMapper 映射. 我们的功能是先映射,再只查询映射好 ...

  8. cssrelative

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  9. MockBean 单元测试

    案例一 官方文档:https://docs.spring.io/spring-boot/docs/2.0.4.RELEASE/reference/htmlsingle/ import org.juni ...

  10. 激光三角测量(sheet of light)halcon示例详解 Reconstruct_Connection_Rod_Calib.hdev 三维重建

    原文作者:aircraft 原文链接:https://www.cnblogs.com/DOMLX/p/11555100.html 前言:最近项目用到halcon的3d模板匹配,三维重建,相机标定,所以 ...