Issue
I just wondering what is the difference between initializing formGroup inside the class or inside the constructor.
Creating them when we are declaring them like this:
form: FormGroup = this.formBuilder.group({})Declare its variable and then create them in
constructorofclassform: FormGroup; constructor(private formBuilder: FormBuilder) { this.form = this.formBuilder.group({}) }
Are there any differences between these two approaches and what are the pros and cons of these two approaches?
Solution
What you showed is the same approach (inlined initialization will be moved to the constructor by the compiler).
Using the FormBuilder in itself is a short form though.
form: FormGroup = new FormGroup({
c1: new FormControl('')
});
==
form: FormGroup = this.fb.group({
c1: ['']
});
Answered By - Gunnar B.
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.