Last active
October 21, 2024 10:06
-
-
Save Armenvardanyan95/c8ad1b65fcb6d85645634e45c9b9372c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component({ | |
| template: ` | |
| <form #form="ngForm" (submit)="onSubmit(form)"> | |
| <input type="text" name="name" [(ngModel)]="controls.name" /> | |
| <input type="email" name="email" [(ngModel)]="controls.email" /> | |
| <input type="number" name="age" [(ngModel)]="controls.age" /> | |
| <button type="submit">Submit</button> | |
| </form> | |
| `, | |
| }) | |
| export class FormComponent { | |
| private readonly userService = inject(UserService); | |
| controls = { | |
| name: signal(''), | |
| email: signal(''), | |
| age: signal(0), | |
| }; | |
| onSubmit(form: NgForm) { | |
| // we can find out everything | |
| // about the form | |
| if (form.valid) { | |
| this.userService.addUser(form.value); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment