簡體   English   中英

Angular-替換jQuery

[英]Angular - replacing jQuery

我試圖在我的代碼中通過jQuery使用Anuglar,並開始痛苦的過渡。

在我的AppComponent中,我有:

HTML:

 <div class="login-wrapper toggle-content">
    <button class="close" type="button"><span aria-hidden="true">×</span></button>
     <iframe
        id="loginframe"
        [src]="framesrc"
        width="100%"
        height="100%"
      >Loading...</iframe>
</div>

jQuery的:

/* --------- Login widget toggle ----------- */
$(document).on('click', '#loginButton', function () {

  console.log("loginButton clicked");
  if (can3rdparty) {
    $('.toggle-content').slideToggle();
  } else {
    var popup = window.open(this.framesrc, '_blank', 'height=500,width=900');
  }
});

如何為此使用純Angular / JavaScript?

<button #viewChildHandle (click)="myFunction" class="close" type="button"><span aria-hidden="true">×</span></button>

在控制器類中,您需要使用@ViewChild批注獲取元素的句柄。 然后,當您擁有句柄時,可以使用jQuery包裝viewChild元素,就像使用jQuery包裝普通HTML元素一樣。

myFunction() {
   $(viewChildEl).slideToggle();
}

暫無
暫無

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

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