'Angular2 call function in html from Component
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.
Solution 1:[1]
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
Solution 2:[2]
Not sure if this was ever solved for by you.
But I use {{ functionName() }} and just return back the information i need.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Pardeep Jain |
| Solution 2 | Andrew Ice |
