I just recently started using angular 4 instead of angular.js 1.
I have followed the heroes tutorial to learn about the fundamentals of angular 4 and I am currently
Try this:
constructor( public router: Router,) {
this.route.params.subscribe(params => this._onRouteGetParams(params));
}
this.router.navigate(['otherRoute']);
You should inject Router in your constructor like this;
constructor(private router: Router) { }
then you can do this anywhere you want;
this.router.navigate(['/product-list']);
You may have enough correct answers for your question but in case your IDE gives you the warning
Promise returned from navigate is ignored
you may either ignore that warning or use this.router.navigate(['/your-path']).then()
.
Redirection in angularjs 4 Button for event in eg:app.home.html
<input type="button" value="clear" (click)="onSubmit()"/>
and in home.componant.ts
import {Component} from '@angular/core';
import {Router} from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.home.html',
})
export class HomeComponant {
title = 'Home';
constructor(
private router: Router,
) {}
onSubmit() {
this.router.navigate(['/doctor'])
}
}
Angular Redirection manually: Import @angular/router
, Inject in constructor()
then call this.router.navigate()
.
import {Router} from '@angular/router';
...
...
constructor(private router: Router) {
...
}
onSubmit() {
...
this.router.navigate(['/profile']);
}
componene.ts-
------------------------------------------------------------------------
import {Router} from '@angular/router';
constructor(private router: Router) {}
OnClickFunction()
{
this.router.navigate(['/home']);
}
component.html-
-----------------------------------------------------------------------------------
<div class="col-3">
<button (click)="OnClickFunction()" class="btn btn-secondary btn-custom mr-
3">Button Name</button>
</div>