Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Armenvardanyan95/f6ad325ad1dee0b50c9f0ef7bd529ba2 to your computer and use it in GitHub Desktop.
Save Armenvardanyan95/f6ad325ad1dee0b50c9f0ef7bd529ba2 to your computer and use it in GitHub Desktop.
@Component({
selector: 'app-some-component-with-form',
template: `...` // our form is here
})
export class SomeComponentWithForm {
public form: FormGroup;
public movies: Array<Movie>
constructor(private formBuilder: FormBuilder){
this.form = formBuilder.group({
firstName: ['', Validators.required],
lastName: ['', Validators.required],
age: ['', Validators.max(120)],
favoriteMovies: [[]], /*
we'll have a multiselect dropdown
in our template to select favorite movies
*/
});
}
public onSubmit(values: User){
/*
now we will just create a new User instance from our form,
with all the data manipulations done inside the constructor
*/
let user: UserModel = new UserModel(values);
// then we will send the user model data to the server using some service
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment