Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to redirect or call routerlink in ts file in angular2

Tags:

This is angular 2 routing code

     <nav>          <ul class="nav nav-tabs">         <li role="presentation" class="active"><a routerLink="/dashboard" routerLinkActive="active">Step I</a></li>         <li role="presentation"> <a routerLink="/faculty" routerLinkActive="active">Step II</a></li>         <li role="presentation"><a routerLink="/heroes" routerLinkActive="active">Step III</a></li>         </ul>               </nav>     <router-outlet></router-outlet> 

button click event

clickFunctionEvent(value: any) {        this.dataService.setFacultyAnswer(JSON.stringify(value)).subscribe(       tradeshows => {             this.data= tradeshows          //if data=success then redirect to next routerLink like "/faculty"                          },       error => {console.error('QuestionList:\n\t ' + error);}     ); } 

if data=success then redirect to next routerLink like "/faculty"

so how to it in .ts file

And how to disable previous routerLink so not allow to go back

thanks in advance

like image 355
kokadwarprafulla Avatar asked Feb 07 '17 04:02

kokadwarprafulla


People also ask

Can we give routerLink to div?

Yes it can be attached to div tag, your route is probably wrong try add / in front of route.


Video Answer


1 Answers

you use

 //in your constructor   constructor(public router: Router){}  //navigation link.  this.router.navigate(['your-route']); 
like image 81
Parth Ghiya Avatar answered Oct 24 '22 08:10

Parth Ghiya