簡體   English   中英

來自組件的 html 中的 Angular2 調用函數

[英]Angular2 call function in html from Component

從我的 angular2 組件中,我想在我的 html 頁面中運行一個函數。

示例:

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

這是需要的,因為我正在將我的應用程序集成到第三方的 html 頁面中。 我需要在應用程序中完成的事件上更新它們。

在下面,我設法使用 window.doAlert(); 有沒有使用 window.open 的替代方法?

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

我從你的問題中假設你被困在 angualr 中的事件綁定,所以試試這個 -

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

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

這是工作示例http://plnkr.co/edit/4UPlh9Pn42yM3VPqYvoL?p=preview更多請參閱此處

不知道你是否曾經解決過這個問題。

但我使用 {{ functionName() }} 並返回我需要的信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM