-
Notifications
You must be signed in to change notification settings - Fork 1
User Input
Aakash Goplani edited this page Jul 28, 2019
·
12 revisions
Taking input from user
Shadow DOM
View Encapsulation
ng-content
-
Template Reference Variable
- A template reference variable is often a reference to a DOM element within a template. It can also refer to a directive (which contains a component), an element, TemplateRef, or a web component.
- Use the hash symbol
#
to declare a reference variable. The following reference variable,#player
, declares a player variable on an<input>
element. - You can refer to a template reference variable anywhere within the component's template. Here, a
<button>
further down the template refers to the player variable.
<input #player placeholder="player name"> <button (click)="playerDetails(player.value)">Call</button>
playerDetails(playerName: HTMLInputElement) { this.playerName = playerName.value; }
-
Event Binding
<form (ngSubmit)="onSubmit($event)">
<input name="player" value="Name">
</form>
onSubmit(event: any) {
return event.target.player.value;
}
Without Form
- Event Binding
<input (keyup)="onKey($event)">
onKey(event) {const inputValue = event.target.value;}
- use
ngModel
i.e 2-way data binding
<input type="text" [(ngModel)]="someString">
someString: string = '';