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?
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.
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.
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]"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With