Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

angular mat-button link to external url

Angular 6 (https://angular.io/) new Project, utilizing the Material Components (https://material.angular.io/) ~ How can I navigate to an external URL from a mat-button component.

HTML

<button mat-button [matMenuTriggerFor]="menu">Menu</button> <mat-menu #menu="matMenu">   <button mat-menu-item>Item 1</button>   <button mat-menu-item>Item 2</button> </mat-menu> 

Typescript

import {Component} from '@angular/core';  @Component({   selector: 'menu-overview-example',   templateUrl: 'menu-overview-example.html',   styleUrls: ['menu-overview-example.css'], })   export class MenuOverviewExample {} 

Live Edtior: https://stackblitz.com/angular/maeymnkvlrq

I believe I am missing something obvious as a novice but am unable to find an answer to my question.

like image 700
PCorruthers Avatar asked May 26 '18 15:05

PCorruthers


People also ask

What is correct to attach a link for Button in angular?

Link can be added to the Button by adding e-link using cssClass property and <a> tag with href attribute should be added inside the button element.

What is Mat button in angular?

The <mat-button>, an Angular Directive, is used to create a button with material styling and animations. In this chapter, we will showcase the configuration required to draw a button control using Angular Material.

What is Mat button?

Angular directing <mat-button> is used to create a button with content styling and animations. Angular content buttons are native <button> or elements enhanced with styling and ink ripples. Native <button> and <a> elements are used to provide the accessible experience for users.


2 Answers

You can change the button attribute to an a with the same design of a button

<button mat-button [matMenuTriggerFor]="menu">Menu</button>  <mat-menu #menu="matMenu">    <a href="http://www.google.com" mat-menu-item>Item 1</a>    <button mat-menu-item>Item 2</button>  </mat-menu>
like image 178
Takatalvi Avatar answered Sep 18 '22 08:09

Takatalvi


Use something like this for a button towards an external URL :

<a mat-raised-button href="https://stackoverflow.com/">Stackoverflow</a> 
like image 43
Al Caulique Avatar answered Sep 19 '22 08:09

Al Caulique