last day (152 days later) » 

3:20 PM
Here is the thing, I'm on a tutorial, which is really good. I'm on the "Forms" part of the tutorial, and it describes the 2 ways to build a form : model/template driven.
It explains things on how to build a form with both ways, and mixing them, this is what makes me confused... actually I come to this kind of code, and I think I'm writing too much things...
register.form.component.html
<h2>Sign up</h2>
<form (ngSubmit)="register()" [formGroup]="userForm">
	<div>
		<label>Username : </label>
		<input name="username" [formControl]="usernameCtrl" [(ngModel)]="user.username" required/><br/>
		<div *ngIf="usernameCtrl.dirty && usernameCtrl.hasError('minlength')">Username length should be at least 3!</div>
		<div> Username value : {{user.username}}</div>
	</div>
	<div>
		<label>Password : </label>
		<input type="password" name="password" [formControl]="passwordCtrl" [(ngModel)]="user.password"/><br/>
and here is the component .ts :
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, FormControl, Validators } from '@angular/forms';

class User {
	username: string;
	password: string;
}
@Component({
	selector: 'ns-register',
	templateUrl: 'templates/register.form.component.html',
})

export class RegisterFormComponent{
	user = new User();
	userForm: FormGroup;
	usernameCtrl: FormControl;
	passwordCtrl: FormControl;
	constructor(fb: FormBuilder){
		this.usernameCtrl = fb.control(this.user.username,
							Validators.compose([
 
3:41 PM
hi @Sambasiva
 

  last day (152 days later) »