angular - Inject Router using Injector.resolveAndCreate inside a class -
is possible inject router using injector.resolveandcreate() ?
import {exceptionhandler, injectable, inject,injector} 'angular2/core'; import {router,router_primary_component} 'angular2/router'; @injectable() export class myexceptionhandler implements exceptionhandler{ constructor(public router: router) { } call(error, stacktrace = null, reason = null) { console.log("error >> " + error); console.log("stacktrace >> " + stacktrace); console.log("reason >> " + reason); let injector: = injector.resolveandcreate([router]); let router: router = injector.get(router); router.navigatebyurl('/error'); } }
getting exception: error during instantiation of token routerprimarycomponent! (e -> router -> routeregistry -> token routerprimarycomponent).
sure, if use injector has router_providers
registered, don't want a router
instance the router
instance - 1 used in application. need use same injector
angular application uses.
this might looking redirect different component inside @canactivate in angular2
Comments
Post a Comment