0

I am working on an interesting project where I use a browser application to open my site "www.mysite.com" and inject there a string into a hidden <input> element. The site is programmed in angular 6 and I would like to create a service that listens to the "onChange()" event of the input. I know it can be done easily by using @Input() for example or anything like that but the difficulty here is that the data comes from a browser application that opens the page and injects the string into the <input> element.

So if the <input> element (or any other element with change detection) has the text stored inside it that comes from the extension I want to use a service to notify other components like a simple textarea inside a component to show the data. Basically I need a way to detect the change and via a service.

Thanks!

5
  • If your objective is to multicast the data use RXJS's Subject or BehaviorSubject .Have a look at this
    – Vikas
    Sep 3, 2018 at 16:16
  • medium.com/@pandukamuditha/…
    – Vikas
    Sep 3, 2018 at 16:17
  • angular.io/guide/…
    – Vikas
    Sep 3, 2018 at 16:17
  • @Vikas: Thanks for the tipp! It will help with the update of the components. However i need to detect the change on the input element and than propagate it to the service. So the browser extension injects the string into the input element (needs to be plain input as browser extension can only inject into plain html elements) and then I need to listen to the "onChange()" event of the input via a service. I dunno if I formulated it good enough? If not I try again?
    – Florian
    Sep 4, 2018 at 6:53
  • why don't you bind change event to a method of your service and multicast the data using BehaviorSubject?
    – Vikas
    Sep 4, 2018 at 9:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.