Skip to content

Instantly share code, notes, and snippets.

@isaurssaurav
Created March 25, 2017 13:20
Show Gist options
  • Select an option

  • Save isaurssaurav/7424c9e0bf81d13b362ff3bbe642c52c to your computer and use it in GitHub Desktop.

Select an option

Save isaurssaurav/7424c9e0bf81d13b362ff3bbe642c52c to your computer and use it in GitHub Desktop.
angular2 navigate from function or code
import { Component, OnInit } from '@angular/core';
import {Router} from '@angular/router';
@Component({
selector: 'app-user',
template: `<h1>user component</h1>
<a [routerLink]="['']">Home</a>
<button (click)="onNavigate()">Go Home</button>
`,
})
export class UserComponent implements OnInit {
constructor(private router:Router) { }
ngOnInit() { }
onNavigate(){
this.router.navigate(['/']);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment