0

I'm learning Angular@1.6.4, I try to do a routing with $routeParams.

(() => {
 'use strict'

 config.$inject = ['$routeProvider','$locationProvider', '$routeParams']
  function config ($routeProvider, $locationProvider, $routeParams) {

   $routeProvider
    .when('/:category', {
      template : `<star-wars-component category="'${$routeParams.category}'"></star-wars-component>`
    })
    .otherwise({
      redirectTo : '/'
    })

   $locationProvider.html5Mode(true)
  }

  angular
    .module('starWarsApp')          
    .config(config)

})()

It goes perfectly until I inject $routeParams, then angular throw me this :

Error: $injector:unpr Unknown Provider Unknown provider: $routeParams

I tried to fix it but I don't really understand why angular throw that error if I inject $routeParams and I'm using ngRoute.

DanyNsg
  • 355
  • 3
  • 10
  • Did you include it while defining angular module e.g., `angular.module('starWarsApp', [ 'ui.router', ... ])` – mintuhouse Apr 20 '17 at 01:25
  • 3
    you can't use `$routeParams` in the `.config` block, you can only use providers. services like `$routeParams` aren't initialized yet. – Claies Apr 20 '17 at 01:27
  • 2
    in this case, your route needs a controller, and that controller needs the `$routeParams` to provide them to the template, not the `.config`. – Claies Apr 20 '17 at 01:29

0 Answers0