0

From my angular2 component, I would like to run a function in my html page.

Example:

<script> 
   function doAlert(){
      alert("in doAlert");
   }
</script>

This is needed as i am integrating my app into a html page for a third party. And i need to update them on events done in the app.

In the below, i manage to do this using window.doAlert(); is there an alternative to using window.

http://plnkr.co/edit/vZtjbATax5yvmwJVWRrJ?p=preview

Roninio
  • 1,761
  • 1
  • 17
  • 24
  • 1
    Please elaborate a bit more what you actually try to accomplish. From you question I'm not able to figure what problem you're actually trying to solve. – Günter Zöchbauer Apr 24 '16 at 11:18
  • 2
    If you want to use `window` just use it like you actually do. There is nothing special to use `window` in Angular2. – Günter Zöchbauer Apr 24 '16 at 11:31
  • How are you integrated with the this party library? Does it support a module loader like commonjs? Regarding `window`, this question could perhaps help you: http://stackoverflow.com/questions/34177221/angular2-how-to-inject-window-into-an-angular2-service. – Thierry Templier Apr 24 '16 at 12:40

2 Answers2

0

i assumed from your question you are stuck on event binding in angualr so try this-

<button (click)='demoFun()'> Button </button>

demoFun(){
//your code..//
}

here is working example http://plnkr.co/edit/4UPlh9Pn42yM3VPqYvoL?p=preview for more refer see here

Pardeep Jain
  • 84,110
  • 37
  • 165
  • 215
0

Not sure if this was ever solved for by you.

But I use {{ functionName() }} and just return back the information i need.

Andrew Ice
  • 831
  • 4
  • 16