簡體   English   中英

如何在 Web 組件(自定義元素)上調用方法

[英]How to call a method on a Web Component (Custom Element)

我有一個我想使用的 web 組件(我無法更改):

我這樣顯示它:

<custom-element #mycustomElement id="customElement"></custom-element>

然后,在 ts 部分,我想調用一個名為“ action ”的特定方法

我試過這個:

 @ViewChild('mycustomElement ', { static: true })
 mycustomElement : ElementRef<HTMLInputElement> = {} as ElementRef;


 this.mycustomElement.nativeElement.action('someMethod' , {});  // this doesnt work

但我有這個錯誤:

類型 HTMLInputElement 上不存在屬性“操作”

建議??

將變量類型設置為組件,然后調用它的 function

@ViewChild('mycustomElement ', { static: true }) myCustomElement : MyCustomElement;

this.myCustomElement.someMethod();

暫無
暫無

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

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