前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >angular的数据绑定条件判断

angular的数据绑定条件判断

作者头像
世间万物皆对象
发布2024-03-20 19:58:54
680
发布2024-03-20 19:58:54
举报
文章被收录于专栏:startstart
html文件

代码语言:javascript
复制
//条件判断:*ngIf是直接影响元素手否被渲染,而非控制元素的显示和隐藏
//*ngIf=“”   html文件
<div *ngIf="falg">
    <p>falg为true</p>
</div>
<div *ngIf="bool">
    <p>bool为false</p>
</div>

循环语句:*ngFor 
<div *ngFor="let item of colors ">
    {{item}}
</div>

Switch语句:[ngSwitch]=”变量“
<div [ngSwitch]="isMax">
    <p *ngSwitchCase="true">
        true
    </p>
    <p *ngSwitchCase="false">
        false
    </p>
    <p *ngSwitchDefault>
        默认
    </p>
</div>

事件绑定:(事件类型)="方法名"
<input #userName type="text" (keyup)="keyUpFn($event)">
<div (click)="keyUpFn($event)" *ngFor="let item of colors ">
    {{item}}
</div>

<!-- 模板引用变量 -->:#name
<button (click)="getUserName(userName.value)">获取userName</button>
xxxxxx.component.ts文件

数据定义,事件都写在这个文件里

代码语言:javascript
复制
// component.ts文件  
import { Component, OnInit } from '@angular/core';
@Component({
  selector: 'app-my-test',
  templateUrl: './my-test.component.html',
  styleUrls: ['./my-test.component.css']
})
export class MyTestComponent implements OnInit {
  falg = true
  bool = false
  ngOnInit() {
  }
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2024-03-20,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • html文件
  • xxxxxx.component.ts文件
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档