단방향 바인딩 - 이벤트(체크박스/select)
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = '이벤트 바인딩 실습';
flag = false;
callPhone(phonenumber: string): void {
console.log(phonenumber);
}
change(fruit: string): void {
console.log(fruit);
}
check(bool: boolean): void {
console.log(bool);
this.flag = bool;
}
}
app.component.html
<h1>{{ title }}</h1>
<h2>input실습</h2>
<input #phone placeholder="phonenumber" /><br />
<button (click)="callPhone(phone.value)">Call</button>
<h2>select 실습</h2>
<select #fruit (change)="change(fruit.value)">
<option>바나나</option>
<option>사과</option>
<option>옥수수</option>
<option>감자</option>
</select>
<h2>checked 실습</h2>
전체 <input type="checkbox" #all (click)="check(all.checked)" /><br />
야구 <input type="checkbox" value="야구" [checked]="flag" /><br />
축구 <input type="checkbox" value="축구" [checked]="flag" /><br />
실행화면