Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add routerlink with string interpolation in angular

I need to add

    router= "/update/id" in my code, where "id" has to be rendered dynamically based on values by *ngFor directive. (i.e) {{obj.id}}.So that id gets rendered dynamically

How to do this?

like image 654
Mohammed Ajmal Avatar asked Sep 19 '18 06:09

Mohammed Ajmal


People also ask

What is string interpolation in angular with an example?

String Interpolation in Angular 8 is a one-way data-binding technique that is used to transfer the data from a TypeScript code to an HTML template (view). It uses the template expression in double curly braces to display the data from the component to the view.

Can we add routerLink to button?

Using Router linksAfter Angular v4 we can directly add a routerLink attribute on the anchor tag or button. Consider the following template, where routerLink attribute added to the anchor tag. The routerLink directive on the anchor tags give the router control over those elements.


1 Answers

You can either use String Interpolation

routerLink="/update/{{obj.id}}"

or Attribute Binding Syntax:

[routerLink]="'/update/' + obj.id"

or as Pankaj suggested, Attribute Binding Syntax like this:

[routerLink]="['/update', obj.id]"
like image 68
SiddAjmera Avatar answered Sep 28 '22 05:09

SiddAjmera