Reputation: 151
I am trying to run a function when a button is clicked that will prep a variable and then at the end of the function redirect to another component and pass that variable. (I want functionality similar to the RouterLink in HTML but from the typescript) I already know how to get the function to run and prep the variable but do not know how to send that variable to a new route (component) from the typescript.
Upvotes: 1
Views: 2009
Reputation: 4333
Add (click)="myFunction()"
on your component HTML.
Import the Angular Router service in your component: import { Router } from '@angular/router';
Inject the router in your component constructor like this: constructor( private router: Router, ...) { }
And then define myFunction
such as:
myFunction(){
this.router.navigate(['/myPath']);
}
Upvotes: 4