I'm trying navigate to new page when get answer from server:
import {Component} from '../../node_modules/angular2/core';
import {Router} from "../../node_modules/angular2/router";
import {Http, Headers, HTTP_PROVIDERS} from '../../node_modules/angular2/http'
@Component({
selector: 'test-page',
templateUrl:'src/login/test.html',
providers: [HTTP_PROVIDERS]
})
export class TestPage {
constructor(private _router:Router,
private _http:Http) {
}
Test(username, password) {
let body = 'test';
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
this._http.post('/api/test', 'test', {headers: headers})
.subscribe(
response => {
this._router.navigateByUrl('Home'); //'this' is not a component
},
error => {
console.log(error)
}
);
}
}
But by some reason 'this' is not a pointer to component but it's a subscribe. Does someone know the reason of issue?