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]);
}
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]);
}
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>
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]);
}
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)]"