Having trouble with using this.router.navigate.
Here is the content of my app.module.ts file:
import {NgModule, NgModuleMetadataType} from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import { HttpModule } from '@angular/http';
...
import {routing} from "./app.routing";
import {entry} from "./entry.component";
imports: [
BrowserModule,
FormsModule,
routing,
HttpModule,
],
Next is the Test component:
import { Component } from '@angular/core';
import {HttpClient} from "./HttpClient.component";
import {Router} from "@angular/router-deprecated";
@Component({
templateUrl: 'templates/entry.html'
})
export class entry {
...
constructor(head:HeaderComponent, private httpClient: HttpClient, private router: Router) {
this.httpClient = httpClient;
}
nav_test(){
this.router.navigate(['search']);
}
}
Followed by the app.routing content:
import { Routes, RouterModule } from '@angular/router';
const appRoutes: Routes = [
{
path: '',
redirectTo: '/home',
pathMatch: 'full',
},
{
path: 'home',
component: HomeComponent
},
{
path: 'search',
component: SearchComponent
}
];
export const routing = RouterModule.forRoot(appRoutes, {useHash: true});
At the end, I am encountering this error:
EXCEPTION: Error: Uncaught (in promise): EXCEPTION: Error in ./entry class entry_Host - inline template:0:0 ORIGINAL EXCEPTION: No provider for Router!
Thank you for your help!