# 1 : 方法声明
No 1:
export class HomeComponent implements OnInit {
public msg:ang;
constructor() {
this.msg = "方法声明1";
}
ngOnInit() {
}
getMsg(){
alert(this.msg);
}
}
No 2:
public userName = "张三";
setName(){
this.userName = "李四 ---改变后的值";
}
No 3 :public flag = true ;
No 4 :
keyupFn(e){ //e事件对象
if( e.keyCode == 13){
alert("按了回车");
}
}
# 2 : 方法执行
No 1 : <button (click)='getMsg()'>执行方法1</button>
No 2 : <button (click)='setName()'>执行方法2</button>
No 3: <button (click)='flag = !flag'>执行方法改变flag【true - false】</button>
No 4 :<input type="text" (keyup)='keyupFn($event)'> 表单处理
No 5: <button (click) = "saved = true"> </button>
![](https://img.haomeiwen.com/i8447227/0f17ab77d84f6d19.png)
网友评论