Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  12] [ 7]  / answers: 1 / hits: 15350  / 8 Years ago, fri, february 26, 2016, 12:00:00

I am currently learning AngularJS & Ionic by creating a simple podcast app.
I am trying to use routeParams to get the itemId but I am getting the following error:





Error: [$injector:unpr] Unknown provider: $routeParamsProvider <- $routeParams <- DetailsController
http://errors.angularjs.org/1.4.3/$injector/unpr?p0=%24routeParamsProvider%20%3C-%20%24routeParams%20%3C-%20DetailsController
minErr/





Now this is how I pass the itemId





  .state('ted', {
url: '/ted/:itemId',
templateUrl: 'templates/ted-talks.html',
controller: 'DetailsController'
})





and here is my controller:





starter.controller(DetailsController, [$scope, $routeParams, $http, function ($scope, $routeParams, $http) {
$http.get('http://api.npr.org/query?id=57&apiKey={I've taken the ID off})
.success(function(data, status, headers, config){
var x2js = new X2JS();
var jsonOutput = x2js.xml_str2json(data);
console.log(jsonOutput);

$scope.stories = jsonOutput.nprml.list.story;

if($routeParams.itemId) {
console.log('Single page id' + $routeParams.itemId);
}


})
.error(function(data, status, headers, config){
alert('There is a problem');
})
}]);





Any ideas what causes this error? I belive that the routeParams is already included in the ionic framework as the demos they provide seem to work, bu I can't figure out how.



Any help is much appreceated :)


More From » angularjs

 Answers
127

As you are using Angular-ui-router you should use $stateParams dependency instead of $routeParams which are meant to use for ui-router(Angular ui-router $stateProvider)



if($stateParams.itemId) {
console.log('Single page id' + $stateParams.itemId);
}



$routeParams is available there for ngRoute module(AngularJS
routing $routerProvider)



[#63138] Thursday, February 25, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ryderalfonsos

Total Points: 655
Total Questions: 88
Total Answers: 91

Location: Nauru
Member since Thu, Feb 2, 2023
1 Year ago
ryderalfonsos questions
Mon, Sep 9, 19, 00:00, 5 Years ago
Wed, Feb 13, 19, 00:00, 5 Years ago
Tue, Feb 12, 19, 00:00, 5 Years ago
Fri, Dec 28, 18, 00:00, 6 Years ago
;