11

私は現在、簡単なポッドキャストアプリケーションを作成してAngularJS & Ionicを学習しています。今これは私が "のitemId"

.state('ted', { 
 
    url: '/ted/:itemId', 
 
    templateUrl: 'templates/ted-talks.html', 
 
    controller: 'DetailsController' 
 
    })
を渡す方法です

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/

: 私は "のitemId" を取得するためにrouteParamsを使用しようとしていますが、私は次のエラーを取得しています

ここは私のコントローラです:

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'); 
 
    }) 
 
}]);

このエラーの原因を任意のアイデア?私はrouteParamsがイオンフレームワークに既に含まれていると信じています。彼らが提供するデモがうまくいくように見えるので、私は方法を理解できません。

すべてのヘルプは非常にappreceatedさ:)

答えて

27

あなたがAngular-ui-routerを使用しているとして、あなたはui-router(角度UI-ルータ$stateProvider)のために使用することが意図されている代わりに$routeParams$stateParams依存関係を使用する必要があります

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

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

+1

あなたはどれくらいの間私が頭を叩いているのか分かりません。本当にありがとう! コントローラーにパラメーターを渡そうとしていて、何も動いていませんでした。... – dannio

+0

@dannio私が助けてくれたことを嬉しく思っています。ありがとう:) –