3
votes

I have been provided with a component which is simply a +/- counter. I can get a reference to the value I need from this component like this:

<sas-plus-minus value="0" min="0" max="99" #adultCount></sas-plus-minus>
{{ adultCount.val }}

adultCount.val displays the correct value from the sas-plus-mins component, but I don't know how to watch for changes in this value within the parent component. It would be quite difficult for me to modify this child component's code, in which I would probably use an Output() to notify the parent of the change.

How can I register a wathcer in my parent component for this sas-plus-minus's val?

1
You can't avoid an event emitter. Either by an @Output or a Subject, but you will have to rely on events.user4676340
why can not edit you component code ??? you should right ?Pranay Rana

1 Answers

-1
votes

You can put a listener on this:

<sas-plus-minus (change)="detect($event)" value="0" min="0" max="99" #adultCount [(ngModel)]="adultCount"></sas-plus-minus>

If (change) doesnot work put (ngModelChange) instead. And in your .ts file:

detect(event){console.log(event);}

And you can derive value from event.