Created
June 26, 2017 19:25
-
-
Save jinalshah999/19b67c8c3ee0beec4276e92fe7663b92 to your computer and use it in GitHub Desktop.
This file contains 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, OnInit } from '@angular/core'; | |
import { FormGroup,FormBuilder,Validators,FormControl } from '@angular/forms'; | |
@Component({ | |
selector: 'app-products', | |
templateUrl: './products.component.html', | |
styleUrls: ['./products.component.css'] | |
}) | |
export class ProductsComponent implements OnInit { | |
myForm:FormGroup; | |
constructor(private formbuilder:FormBuilder) { } | |
onSubmit(){ | |
this.allProduct.push(this.myForm.value); | |
} | |
ngOnInit() { | |
this.myForm=this.formbuilder.group({ | |
'p_id':['',Validators.required], | |
'pname':['',[Validators.required,this.exampleValidator]], | |
'pprice':['',[Validators.required,Validators.min(0)]], | |
'pimg':['',Validators.required], | |
'soh':['',[Validators.required,Validators.max(10)]] | |
}); | |
} | |
exampleValidator(control:FormControl):{[s: string]: boolean}{ | |
if(control.value==="Example"){ | |
return {example:true}; | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment