Created
May 19, 2016 03:44
-
-
Save niisar/45a9c3e451e77e4e0f79b617d42dea55 to your computer and use it in GitHub Desktop.
DI - Class constructor injection
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
| import { Component } from '@angular/core'; | |
| import { Control, Validators, FormBuilder } from '@angular/common'; | |
| @Component({ | |
| moduleId: module.id, | |
| selector: 't3-app', | |
| templateUrl: 't3.component.html', | |
| styleUrls: ['t3.component.css'] | |
| }) | |
| export class T3AppComponent { | |
| form; | |
| constructor(private formBuilder: FormBuilder) {} | |
| ngOnInit(){ | |
| this.form = this.formBuilder.group({ | |
| 'medium': new Control('Movies'), | |
| 'name': new Control('',Validators.compose([ | |
| Validators.required, | |
| Validators.pattern('[\\w\\-\\s\\/]+'), | |
| ])), | |
| 'year': new Control('',this.yearValidation) | |
| }); | |
| } | |
| yearValidation(control){ | |
| if(control.value.trim().length === 0) return null; | |
| var year = parseInt(control.value); | |
| var minYear = 2000; | |
| var maxYear = 2010; | |
| if(year >= minYear && year <= maxYear) return null; | |
| return {'year': {'min':minYear, 'max':maxYear}} | |
| } | |
| title:any; | |
| onSubmit(data){ | |
| this.title = data; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment