简体   繁体   中英

Open new tab when click on a div Angular

I am developping an angular project my problem is that i want when i click into a div i open a new tab but it doesn't work for me. It worked for <a> . Can someone help me ? this is my code:

<div class="application"   target="_blank" routerLink="/home">
    <img class="imgChart " src="./../assets/img/charts.jpg" alt="image 1">
    <div class="title-app">{{'STORE.APPSTAT' | translate}}</div>
    <p>{{'STORE.DESCRIPTIONSTATISTIQUE' | translate}}</p>
</div>

You can open a window by calling the open method on the Window object and passing in a URL.

Componenet.html:

<div class="application" (click)='openNewTab()'>
    <img class="imgChart " src="./../assets/img/charts.jpg" alt="image 1">
    <div class="title-app">{{'STORE.APPSTAT' | translate}}</div>
    <p>{{'STORE.DESCRIPTIONSTATISTIQUE' | translate}}</p>
</div>

Component.ts:

  public openNewTab() {
    window.open('http://www.google.com', '_blank');
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM