Skip to content

Instantly share code, notes, and snippets.

@Armenvardanyan95
Last active October 21, 2024 10:06
Show Gist options
  • Save Armenvardanyan95/c8ad1b65fcb6d85645634e45c9b9372c to your computer and use it in GitHub Desktop.
Save Armenvardanyan95/c8ad1b65fcb6d85645634e45c9b9372c to your computer and use it in GitHub Desktop.
@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