Skip to content

Instantly share code, notes, and snippets.

@Armenvardanyan95
Created July 2, 2017 09:52
Show Gist options
  • Save Armenvardanyan95/2c5e0f5c0294d193b413af6d841fe7b9 to your computer and use it in GitHub Desktop.
Save Armenvardanyan95/2c5e0f5c0294d193b413af6d841fe7b9 to your computer and use it in GitHub Desktop.
@Component({
selector: 'app-some-component-with-form',
template: `
<div [formGroup]="form">
<div class="form-control">
<label>First Name</label>
<input type="text" formControlName="firstName" />
</div>
<div class="form-control">
<label>Last Name</label>
<input type="text" formControlName="lastName" />
</div>
<div class="form-control">
<label>Age</label>
<input type="text" formControlName="age" />
</div>
</div>
`
})
export class SomeComponentWithForm {
public form: FormGroup;
constructor(private formBuilder: FormBuilder){
this.form = formBuilder.group({
firstName: ['', Validators.required],
lastName: ['', Validators.required],
age: ['', Validators.max(120)],
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment