angularcli 第三篇(数据循环*ngFor、条件判断*ngIf)
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)的更多相关文章
- python Django教程 之模板渲染、循环、条件判断、常用的标签、过滤器
python3.5 manage.py runserver python Django教程 之模板渲染.循环.条件判断.常用的标签.过滤器 一.Django模板渲染模板 1. 创建一个 zqxt_tm ...
- vue数据渲染、条件判断及列表循环
1.数据渲染 {{msg}} <template> <div id="app"> {{msg}} </div> </template&g ...
- Java 控制语句:循环、条件判断
基础很重要,基础很重要,基础很重要.重要的事情说三遍,. 程序设计中的控制语句主要有三种:顺序.分支和循环.我们每天写的代码,除了业务相关,里面会包含大量的控制语句.但是控制语句的基本使用,是否有些坑 ...
- ansible 循环与条件判断when
普通循环 with_itemes 变量组 { item } 循环变量 示例 - name: 覆盖配置文件 copy: src=/root/{{ item }} dest=/root/test/{{ i ...
- shell基础篇(五)条件判断
写脚本时:有时要判断字符串是否相等,数字测试.这对后面学习的shell语句,循环,条件语句做好基础. 条件判断格式 1. test condition : test命令 2. [ conditio ...
- Ansible系列(六):循环和条件判断
本文目录:1. 循环 1.1 with_items迭代列表 1.2 with_dict迭代字典项 1.3 with_fileglob迭代文件 1.4 with_lines迭代行 1.5 with_ne ...
- PHP和JS在循环、条件判断中的不同之处
一.条件判断: php中算 false 的情况 1. boolean:false 2. 整形:0 3.浮点型:0 4.字符串:"" "0"(其他都对) 5.空 ...
- angular 中数据循环 *ngFor
<!--The content below is only a placeholder and can be replaced.--> <div style="text-a ...
- Go语言之循环与条件判断
一.for循环 Go 语言中没有 while 循环,只有一个 for 循环 for 变量初始化;条件;变量自增/自减 { 循环体内容 } 1.基本使用 for i := 0; i < 10; i ...
随机推荐
- Linux服务器连接不上的几种解决办法
Linux远程服务器连接不上,或连接超时解决办法:1.测试网络是否通: ping 远程IP 2.如果能ping通则表示与服务器网络连接是正常,接下来测试端口:telnet 远程ip 端口 3.如 ...
- [LeetCode] 1. Two Sum 两数和
Given an array of integers, return indices of the two numbers such that they add up to a specific ta ...
- [LeetCode] 107. Binary Tree Level Order Traversal II 二叉树层序遍历 II
Given a binary tree, return the bottom-up level order traversal of its nodes' values. (ie, from left ...
- [LeetCode] 154. Find Minimum in Rotated Sorted Array II 寻找旋转有序数组的最小值 II
Follow up for "Find Minimum in Rotated Sorted Array":What if duplicates are allowed? Would ...
- namespace Measure
namespace Measure { public delegate void DelegateTrigger(); public class HMeasureSYS : System.IDispo ...
- junit单元测试不通过报documentationPluginsBootstrapper相关异常
这是因为Spring整合springfox-swagger2后导致的,错误信息如下: -- ::, [main] [WARN] [org.springframework.context.support ...
- JAVAWEB实现增删查改(图书信息管理)之修改功能实现
首先通过点击index.jsp页面的修改按钮,获取该行的id:↓ 其次,跳转到updateBooks.jsp页面进行修改信息,页面代码如下:↓ <%@ page import="Boo ...
- 下载安装GO,编辑器GOLand和在GOLand上运行项目的几种方式
下载安装GO 下载GO地址:https://golang.google.cn/dl/,一直下一步下一步的操作. 安装完成之后,会有一个GOPATH(此路径是创建go项目的时候会自动在该文件夹下创建), ...
- 【Linux】一步一步学Linux——Linux系统目录详解(09)
目录 00. 目录 01. 文件系统介绍 02. 常用目录介绍 03. /etc目录文件 04. /dev目录文件 05. /usr目录文件 06. /var目录文件 07. /proc 08. 比较 ...
- golang方法和函数的区别