查看: 107|回覆: 0

angular点击事件和表单事件

[複製鏈接]

4

主題

0

回帖

0

積分

热心网友

金币
0
閲讀權限
220
精華
0
威望
0
贡献
0
在線時間
0 小時
註冊時間
2012-3-8
發表於 2019-5-20 15:48:00 | 顯示全部樓層 |閲讀模式
<div style="text-align:center">
  <h1>
    Welcome to {{ title }}!
  </h1>
  <button class="button" (click)="getData()"> 点击按钮触发事件
  </button>
  <button class="button" (click)="setData()"> 点击按钮设置数据
  </button>
  <input type="text" (keyup)="keyUpFn($event)"/>
</div>
import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss']
})
export class AppComponent {
  title = 'angulardemo';
  status='2';
  isShow=false;
  msg='消息'
  getData(){ /*自定义方法获取数据*/ //获取
    alert(this.msg);
  } 
  setData(){
  //设置值
  this.msg='这是设置的值'; 
  }
  keyUpFn(e){
    console.log(e)
  }
}

效果:

回覆

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即注册

本版積分規則

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部