0

In HTML page

<h2 class="entry-title"><a href="javascript:void(0)" (click)="moreInfo(fashion)">{{fashion.postName}}</a></h2>

In Component.ts

moreInfo(data) {
    this.router.navigate(['/blog-info/', data.postName]);
  }
Edric
  • 24,639
  • 13
  • 81
  • 91
shivlal kumavat
  • 868
  • 1
  • 12
  • 28

3 Answers3

0

you need to add target attribute in your HTML

<h2 class="entry-title"><a target="_blank" href="javascript:void(0)" (click)="moreInfo(fashion)">your template expression</a></h2>
Jasdeep Singh
  • 7,901
  • 1
  • 11
  • 28
0

If you want to do it, you should have href attribute. So, routerLink is a good choice. other way:

<h2 class="entry-title"><a href="/blog-info/{{fashion.postName}}" (click)="moreInfo($event, fashion)">{{fashion.postName}}</a></h2>

moreInfo(event, data) {
    event.preventDefault();
    this.router.navigate(['/blog-info/', data.postName]);
}
HTN
  • 3,388
  • 1
  • 8
  • 18
0

Call function in routerLink. create function in component:

moreInfo(data) {
     return  data.postName.replace(/\s/g, '-') + '-' + data._id;
  }

Use like this in routerLink:

[routerLink]="['/blog-info', moreInfo(fashion)]"
shivlal kumavat
  • 868
  • 1
  • 12
  • 28