i am new to angular2 and i want to trigger a function when the user selects some value in a dropDown. So i tried to implement statusChange of the FormControl class but it is not getting triggered,
wonder how and when to use the statusChange in angular2 this is my code
class policy{
subCategory: FormControl = new FormControl();
ngOnInit() {
this.subCategory.statusChanges.subscribe(
s => {
alert('success');
}, e => {
alert('error');
}, () => {
alert('complete');
}
);
}
}
I thought by implementing statusChanges i can trigger the success function on every change of value on the dropdown, obviously it is now working.
UPDATE 1
I have updated the plunkr
As the comments stated, you probably wanted valueChanges
instead. However, for the thousands of other folks who arrived here from searching for how statusChanges
works, here you go:
this.subCategory.statusChanges.subscribe( (status) => {
console.log(status); //status will be "VALID", "INVALID", "PENDING" or "DISABLED"
})
The docs describe those 4 possible values as follows:
- VALID: This control has passed all validation checks.
- INVALID: This control has failed at least one validation check.
- PENDING: This control is in the midst of conducting a validation check.
- DISABLED:This control is exempt from validation checks. These status values are mutually exclusive, so a control cannot be both valid AND invalid or invalid AND disabled.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With