javascript - ORIGINAL EXCEPTION: No provider for Router! angular 2 RC5 -


can't use this.router.navigate.

this my: app.module.ts

    import {ngmodule, ngmodulemetadatatype}      '@angular/core';     import { browsermodule } '@angular/platform-browser';     import {formsmodule}    '@angular/forms';     import { httpmodule } '@angular/http';     ...     import {routing} "./app.routing";     import {entry} "./entry.component"; imports: [          browsermodule,         formsmodule,         routing,         httpmodule,     ], 

test component

import { component } '@angular/core'; import {httpclient} "./httpclient.component"; import {router} "@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']);     } } 

and app.routing

import { routes, routermodule } '@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}); 

and @ end have error:

exception: error: uncaught (in promise): exception: error in ./entry class entry_host - inline template:0:0 original exception: no provider router!

thank in advance!

issue test component import,

you using

import {router} "@angular/router-deprecated"; 

you should using,

import { router } '@angular/router'; 

hope helps!!


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

mapreduce - Resource manager does not transit to active state from standby -

serialization - Convert Any type in scala to Array[Byte] and back -