[英]Angular2 call function in html from Component
From my angular2 component, I would like to run a function in my html page.从我的 angular2 组件中,我想在我的 html 页面中运行一个函数。
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.这是需要的,因为我正在将我的应用程序集成到第三方的 html 页面中。 And i need to update them on events done in the app.
我需要在应用程序中完成的事件上更新它们。
In the below, i manage to do this using window.doAlert();在下面,我设法使用 window.doAlert(); is there an alternative to using window.
有没有使用 window.open 的替代方法?
http://plnkr.co/edit/vZtjbATax5yvmwJVWRrJ?p=preview http://plnkr.co/edit/vZtjbATax5yvmwJVWRrJ?p=preview
i assumed from your question you are stuck on event binding in angualr so try this-我从你的问题中假设你被困在 angualr 中的事件绑定,所以试试这个 -
<button (click)='demoFun()'> Button </button>
demoFun(){
//your code..//
}
here is working example http://plnkr.co/edit/4UPlh9Pn42yM3VPqYvoL?p=preview for more refer see here这是工作示例http://plnkr.co/edit/4UPlh9Pn42yM3VPqYvoL?p=preview更多请参阅此处
Not sure if this was ever solved for by you.不知道你是否曾经解决过这个问题。
But I use {{ functionName() }} and just return back the information i need.但我使用 {{ functionName() }} 并返回我需要的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.