Angular 2 Form builder validators question

1 view
Skip to first unread message

LearningAngular

unread,
Sep 28, 2017, 8:20:17 PM9/28/17
to Angular2
Hello,

Looking at the code below. 
I'm trying to enter a default value with this line of code controlerSeverity:[2,[]], but i like to make this value more dynamic so rather then hard code the value in this example the number two can I not substitute a variable (second example code)



This works:
 buildDetailsForm() {
    this.DetailsForm = this._fb.group({          
     incidentDescription: ['', []],
     controlerSeverity:[2,[]], // hard coded value works
     createdBy:['',[]]
   });
    }

This does not work, how come?
testValue = 2;

 buildDetailsForm() {
    this.DetailsForm = this._fb.group({          
     incidentDescription: ['', []],
     controlerSeverity:[this.testValue,[]], // can i not use a variable in place of hard coding for example a number??? as of now this wont work.
     createdBy:['',[]]
   });
    }
Reply all
Reply to author
Forward
0 new messages