Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.