Created
July 2, 2017 11:48
-
-
Save Armenvardanyan95/f6ad325ad1dee0b50c9f0ef7bd529ba2 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({ | |
| 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