2

I want to make mat-card to be clickable and when I hover over the mat-card I wanted to show link cursor. There are many cards when I click on one of the cards I want to navigate to another page. How Can I achieve this?

Is it appropriate to use the following code in my template html.

<a mat-card   routerLink= ...>  Buy  </a>

My first attempt was

        <div fxLayout="row rap">
           <mat-card> 
                <mat-card-content> 
                   <div> $100 </div> 
                   <div> 3000 ETB</div>
               </mat-card-content> 
           </mat-card>
        <mat-card> .... </mat-card>
     </div>
Akber Iqbal
  • 14,487
  • 12
  • 48
  • 70
Clickmit Wg
  • 523
  • 2
  • 9
  • 25

3 Answers3

6

<a *ngFor="let card of childCards" [routerLink]="[card?.targetUrl]"> Write mat card code inside anchor tag.

ARMUGHAN ALI
  • 339
  • 3
  • 5
1

Why not wrap the mat-card in a <a> but sure to remove the underline styling on it

relevant HTML:

<a class='removeStyle' href='#'>
    <mat-card class="example-card">
    ....
    </mat-card>
</a>

relevant CSS:

.removeStyle{
  text-decoration: none;
}

complete working stackblitz here

Akber Iqbal
  • 14,487
  • 12
  • 48
  • 70
0

HTML

<mat-card (click)="redirect(100)"> 
    <mat-card-content> 
        <div> $100 </div> 
        <div> 3000 ETB</div>
    </mat-card-content> 
</mat-card>

<mat-card (click)="redirect(200)"> 
    <mat-card-content> 
        <div> $200 </div> 
        <div> 4000 ETB</div>
    </mat-card-content> 
</mat-card>

CSS

mat-card {
  cursor: pointer;
  margin-bottom: 1rem;
}

TS

redirect(id) {
    alert('Called from ' + id);
  }

Working Solution : https://stackblitz.com/edit/angular-zr3tqo