1、数据循环 *ngFor

(1)普通循环

<ul>
<li *ngFor = "let item of list" >
{{ item }}
</li>
</ul>

(2)遍历数组同时获取索引值key

<ul>
<li *ngFor = "let item of list; let i = index;" >
{{ item }} --{{ i }}
</li>
</ul>

(3)template 循环

<ul>
<li template = "ngFor let item of list" >
{{ item }}
</li>
</ul>

例:对象内部嵌套数字,多重循环

<!-- 在compontent.ts 文件里定义数组 -->
export class NewsComponent implements OnInit {

public list:any[];

constructor() {

this.list4=[

{

'catename':"宝马",

"list":[

{'title':'宝马x1'},
{'title':'宝马x3'},
{'title':'宝马x2'},
{'title':'宝马x4'},

]

} ,{

'catename':"奥迪",

"list":[

{'title':'奥迪q1'},
{'title':'奥迪q2'},
{'title':'奥迪q3'},
{'title':'奥迪q4'},
]

},

]

}

ngOnInit() {

}

}

<!-- HTML文件里循环数组 -->
<ul>
<li *ngFor = "let item of list; let i = index;" >
{{ item.dog }} --{{ i }}
<ol>
<li *ngFor = "let cat of item.list" > {{ cat.title }} </li>
</ol>
</li>
</ul>

2、条件判断 *ngIf

<!--条件判断语句-->

<div *ngIf="flag">flag=true的情况下面显示1</div>

<br>

<button (click)='flag=!flag'>执行方法改变flag</button>  <!--取反-->

angularcli 第三篇(数据循环*ngFor、条件判断*ngIf)的更多相关文章

  1. python Django教程 之模板渲染、循环、条件判断、常用的标签、过滤器

    python3.5 manage.py runserver python Django教程 之模板渲染.循环.条件判断.常用的标签.过滤器 一.Django模板渲染模板 1. 创建一个 zqxt_tm ...

  2. vue数据渲染、条件判断及列表循环

    1.数据渲染  {{msg}} <template> <div id="app"> {{msg}} </div> </template&g ...

  3. Java 控制语句:循环、条件判断

    基础很重要,基础很重要,基础很重要.重要的事情说三遍,. 程序设计中的控制语句主要有三种:顺序.分支和循环.我们每天写的代码,除了业务相关,里面会包含大量的控制语句.但是控制语句的基本使用,是否有些坑 ...

  4. ansible 循环与条件判断when

    普通循环 with_itemes 变量组 { item } 循环变量 示例 - name: 覆盖配置文件 copy: src=/root/{{ item }} dest=/root/test/{{ i ...

  5. shell基础篇(五)条件判断

    写脚本时:有时要判断字符串是否相等,数字测试.这对后面学习的shell语句,循环,条件语句做好基础. 条件判断格式  1. test condition : test命令  2. [ conditio ...

  6. Ansible系列(六):循环和条件判断

    本文目录:1. 循环 1.1 with_items迭代列表 1.2 with_dict迭代字典项 1.3 with_fileglob迭代文件 1.4 with_lines迭代行 1.5 with_ne ...

  7. PHP和JS在循环、条件判断中的不同之处

    一.条件判断: php中算  false 的情况 1. boolean:false 2. 整形:0 3.浮点型:0 4.字符串:"" "0"(其他都对) 5.空 ...

  8. angular 中数据循环 *ngFor

    <!--The content below is only a placeholder and can be replaced.--> <div style="text-a ...

  9. Go语言之循环与条件判断

    一.for循环 Go 语言中没有 while 循环,只有一个 for 循环 for 变量初始化;条件;变量自增/自减 { 循环体内容 } 1.基本使用 for i := 0; i < 10; i ...

随机推荐

  1. Sword C语言原子操作

    /* gcc内置原子操作 */ #include <stdio.h> /* 知识补充: gcc 4.1.2版本之后,对X86或X86_64支持内置原子操作.即不需要引入第三方库(如pthr ...

  2. matlab学习笔记11_1低维数组操作

    一起来学matlab-matlab学习笔记11 11_1 低维数组操作repmat函数,cat函数,diag函数 觉得有用的话,欢迎一起讨论相互学习~Follow Me 参考书籍 <matlab ...

  3. [Bayes] Concept Search and LDA

    重要的是通过实践更深入地了解贝叶斯思想,先浅浅地了解下LDA. 相关数学知识 LDA-math-MCMC 和 Gibbs Sampling LDA-math - 认识 Beta/Dirichlet 分 ...

  4. MUD游戏开发教程视频

    MUD游戏开发教程视频 https://space.bilibili.com/476328540/channel/detail?cid=91187

  5. 【linux基础err】NVIDIA-SMI has failed because it could't communicate with the NVIDIA driver.

    问题 安装nvidia driver和cuda关机重启之后出现不能进入系统的问题,进入命令行模式使用nvidia-smi检查驱动的问题. nvidia-smi NVIDIA-SMI has faile ...

  6. 思维导图Xmind8

    Xmind——一款强大的思维导图工具,方便记忆和理清思路,同时思维导图特殊的记录方式也便于捕捉跳跃思考. 五款思维导图软件:MindManager.iMindMap.XMind.MindMapper. ...

  7. python的安装与配置

    pyhton的下载与安装 1.python官网地址:https://www.python.org 2.下载 Python 编辑器PyCharm PyCharm 是一款功能强大的 Python 编辑器 ...

  8. [转帖]DCEP:中国自己的数字货币

    DCEP:中国自己的数字货币 https://cloud.tencent.com/developer/news/435883 前面我们讨论了Libra的革命性和局限性,接下来我想跟你聊一件重要的事,那 ...

  9. 【C++札记】标准输入与输出

    概述 C语言中使用函数scanf和printf作为标准输入和输出,在C++中引入了类cin和cout进行标准输入和输出,所需头文件为<iostream>,命名空间是std.这里所说的标准输 ...

  10. FIFO形成3x3矩阵

    Verilog生成矩阵一般是使用shift_ip核,但其实用两个FIFO也行.最近刚好学到这种方法,把原理总结一下. 要求 现在有10x5的数据和对应数据有效指示信号,数据为0~49,要用FPGA对其 ...