6

Currently I have an Angular 2 component that is being downgraded as a directive and used in a bootstrapped hybrid Angular1/Angular2 application. I'm running into an issue when the component is loaded in the browser I get the following error:

No provider for ActivatedRoute!

Note: the following, No provider for ActivatedRoute - Angular 2 RC5 does not cover this use case.

This app still uses all the routing from the bootstrapped Angular 1 app and has been working just fine thus far; I haven't converted the routing to use the Angular 2 routing at this point. One of my requirements in the new component I built was to inspect query parameters. This could be done with the following code:

import { ActivatedRoute } from '@angular/router';

constructor(
        private route: ActivatedRoute)

route.queryParams.subscribe(
    data => this.Id = data['Id']);

The problem I believe is in the fact that the code above relies on the Angular2 router which as I mentioned is not yet being used in my hybrid bootstrapped application. So here is my question:

  • Can I use the code I have above without using the Angular2 router and still inspect the query string parameters? The original Angular1 controller used $routeParams to get querystring information. This wasn't supported in my new Angular2 component. If the answer to the above is I can't use ActivatedRoute because I'm not using the Angular2 router, should I be trying to use this old method or use another; all I need to do is inspect route parameters in my component?
Community
  • 1
  • 1
atconway
  • 20,624
  • 30
  • 159
  • 229
  • Add ActivatedRoute to providers of your NgModule or make sure RouterModule is added to imports – Babar Hussain Mar 07 '17 at 23:41
  • 1
    @BabarBilal - that doesn't work. I get the error, "Can't resolve all parameters for ActivatedRoute" According to http://stackoverflow.com/questions/40509325/error-systemjs-cant-resolve-all-parameters-for-activatedroute I need to have `imports: [ RouterModule.forRoot(routes) ]` but again I don't have any Angular 2 routes defined as my post says. So this brings me back to my question - can I use `ActivatedRoute` without using Angular 2 routing? – atconway Mar 08 '17 at 05:14
  • No you cant because all routing providers came from RouterModule – Babar Hussain Mar 08 '17 at 08:05
  • If you are not using Angular 2 routing, are you using the AngularJS UI Router? Perhaps you are looking for [URL parameters](https://github.com/angular-ui/ui-router/wiki/URL-Routing)? – Jim Mar 08 '17 at 20:24
  • @jim - no this application used `$routeProvider` – atconway Mar 09 '17 at 03:15

0 Answers0