Tester
Tester

Reputation: 271

angularjs2 29:20 caused by: this._router.navigate is not a function

I am new in angularjs2 and i try to navigate route but i revived "29:20 caused by: this._router.navigate is not a function"

may code like this

import {Component} from '@angular/core';
import { Http } from '@angular/http';
import { ActivatedRoute } from '@angular/router';
import 'rxjs/add/operator/map';

@Component({
selector: 'app-user',
templateUrl: `app/user/user.component.html`
})
export class UserComponent {
constructor(private _http: Http, private _router: ActivatedRoute) { 
}

edit() {
this._router.navigate(['form']);
}
};

Upvotes: 0

Views: 48

Answers (1)

Fredrik Lundin Grande
Fredrik Lundin Grande

Reputation: 8186

You are suppose to use Router, not ActivatedRoute to navigate.

import { Router } from '@angular/router'

...

constructor(private _http: Http, private _router: Router) {}

...

See official docs for more information

Router:

[...] Manages navigation from one component to the next.

ActivatedRoute:

A service that is provided to each route component that contains route specific information such as route parameters, static data, resolve data, global query params and the global fragment.

Upvotes: 1

Related Questions