3

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?

serlingpa
  • 12,024
  • 24
  • 80
  • 130

1 Answers1

-1

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.

AkshayP
  • 106
  • 1
  • 9