niisar
5/18/2016 - 7:18 AM

Validation—built in

Validation—built in

import { Component } from '@angular/core';
import { ControlGroup, Control, Validators } from '@angular/common';
@Component({
  moduleId: module.id,
  selector: 't3-app',
  templateUrl: 't3.component.html',
  styleUrls: ['t3.component.css']
})
export class T3AppComponent {
  form;
  ngOnInit(){
  	this.form = new ControlGroup({
  	  'medium': new Control('Movies'),
  	  'name': new Control('',Validators.compose([
  	  	Validators.required,
  	  	Validators.pattern('[\\w\\-\\s\\/]+')
  	  ]))
  	});
  }
  title:any;
  
  onSubmit(data){
  	this.title = data;
  }
}
<h1>
  {{title | json}} 
</h1>
<form (ngSubmit)="onSubmit(form.value)" [ngFormModel]="form">
	<ul>
		<li>
			<label for="medium">Medium2</label>
			<select name="medium" id="medium" ngControl="medium">
				<option value="Movies">Movies</option>
				<option value="Series">Series</option>
			</select>
		</li>
		<li>
			<label for="name">Name</label>
			<input type="text" name="name" id="name" ngControl="name"/>
		</li>
	</ul>
	<button type="submit" [disabled]="!form.valid ">Save</button>
</form>