Reputation: 23
In Angular Reactive Forms I have form control "name" and form array control "skills", I can add valueChange
subscribe to whole skills, but is there any way to add valueChange
subscribe to "skillname" alone which is inside "skills".
this.exp = this.fb.group({
name: [null, Validators.required],
skills: this.fb.array([
{
skillname: 'java',
experience: 2
},
{
skillname: 'python',
experience: 2
}
]})})
Example:
this.exp.skills.valueChanges.subscribe(skills=>
{ //sample code });
But I need to listen to skillname:
this.exp.skills[0].skillname.valueChanges.subscribe(name=>
{ //sample code });
Like this, is there a way to do this?
Upvotes: 2
Views: 551
Reputation: 1931
this.exp.get('skillName').valueChanges.subscribe(val=>{
console.log(val);
});
Upvotes: 0
Reputation: 2839
you can use get and at functions.
this.exp.skills.at(yourindex).skillname.valueChanges.subscribe(name=>
{ //sample code });
would be
this.exp.get('skills').at(yourIndex).get('skillname').valueChanges.subscribe(name=> {});
Upvotes: 1