Search code examples
javascripthtmlangularnativescriptangular2-nativescript

Is there any equivalent to the HTML anchor tag on Nativescript?


I'm trying to display a simple image or text with a link such as an HTML <a> anchor tag

  <ListView [items]="items | async" (itemTap)="onItemTap($event)">
    <template let-item="item">
      <StackLayout>
        <Image [src]="item.imageUrl" ></Image> 
 <!--<Image [src]="item.imageUrl" href="http://google.com"></Image>-->
      </StackLayout>
    </template>
  </ListView>

It seems the only options is to be using onItemTap and getting the item url and manually setting the url content to be displayed on a separate webview. Are there any tags that would automatically open a separate browser page on the phone and display the URL content of the item?


Solution

  • For your case, you could use openUrl() and on tap Event on some of the components to open the needed page. For example:

    export function onTap(args:EventData){        
        openUrl("https://www.google.com");
    }
    

    You could also review the sample project here.