Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Angular valuechanges #567

Closed
DhimantB opened this issue May 6, 2018 · 2 comments
Closed

Angular valuechanges #567

DhimantB opened this issue May 6, 2018 · 2 comments
Labels
invalid This issue is out of scope or has been deemed invalid

Comments

@DhimantB
Copy link

DhimantB commented May 6, 2018

I have 5 form controls inside the formgroup and I have subscribed the valueChanges method on formGroup.

How can I opt out one formControl from that formGroup not to subscribe with valueChanges? because I have separated logic for that control and that logic will take care all the required things.

Example:

this.myForm = this.fb.group({
id: [, { updateOn: 'change' }],
name: [, { updateOn: 'change' }]
})

this.myForm.valueChanges.subscribe(x=> this.saveChages());

But let's say from the above subscription what if I want to opt out name?

FYI: I would like to avoid subscription for each and every control separately. It led to increase the lines of code so.

Thanks in advance.

Dhimant

@DhimantB
Copy link
Author

DhimantB commented May 7, 2018

Another example

ngOnInit(){

this.myForm = this.fb.group({
	id: [, { updateOn: 'change' }],
    name: [, { updateOn: 'change' }],
    city: [, { updateOn: 'change' }]
})

this.myForm.valueChanges.subscribe(x=> this.saveChages());

this.myForm.get('city').valueChanges.subscribe(x=> this.saveChagesCity());

}

saveChages(): void {

//saving the changes

}

saveChagesCity(): void {

//saving the changes business logic only for city

}

QUESTION:
Here I want to opt out the "city" formControl from calling the saveChages() method.

In the above code, as soon as I change the city, both method is being called which I don't want it.

@Qix-
Copy link
Member

Qix- commented Jun 20, 2018

This has nothing to do with this repository or module.

@Qix- Qix- closed this as completed Jun 20, 2018
@debug-js debug-js locked as off-topic and limited conversation to collaborators Jun 20, 2018
@Qix- Qix- added the invalid This issue is out of scope or has been deemed invalid label Jun 20, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
invalid This issue is out of scope or has been deemed invalid
Development

No branches or pull requests

2 participants