Skip to content

Instantly share code, notes, and snippets.

@luillyfe
Last active August 6, 2019 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luillyfe/742b468242b7d683670b2e4bae1cfa63 to your computer and use it in GitHub Desktop.
Save luillyfe/742b468242b7d683670b2e4bae1cfa63 to your computer and use it in GitHub Desktop.
Controlled Components in Angular
<form class="mx-3">
<div class="form-group">
<label for="email">Email address</label>
<input [ngModel]="email" (ngModelChange)="emailHandler($event)"
name="email" type="email" class="form-control" id="email"
aria-describedby="email" placeholder="Enter email">
<small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
</form>
...
export class AppComponent {
email = "";
constructor() {}
emailHandler(input) {
this.email = input;
console.log(this.email);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment