$routeParams 未定义

$routeParams is undefined

我在 angular JS 方面很菜鸟,我遇到了问题。指令 console.log($routeParams) 显示 routeParams 为空,我不知道为什么。 我使用 ionic yeoman 生成器创建了我的项目。

这在我看来(生成这样的 url http://localhost:8100/#/app/tracking/50

 <p ng-repeat="item in items">
   <a href="#/app/tracking/{{item .number}}" class="item item-icon-left">
     <i class="icon ion-home"></i>
      {{item .a}} - {{item .b}}
   </a>
 </p>

我的路由器配置在app.js

.state('app.tracking', {
    url: "/tracking/:idItem",
data: {
    requireLogin: true
  },
views: {
  'menuContent': {
    templateUrl: "templates/tracking.html",
    controller: 'TrackingCtrl'
  }
}
})

这是我的控制器(我尝试通过这些方式访问)

.controller('TrackingCtrl', function($scope,$routeParams) {

  console.log($routeParams);
  console.log($routeParams.idItem);
  console.log($routeParams["idItem"]);

})

我在这里定义了 ngRoute int app.js

   angular.module('starter', ['ionic','angular-  md5','ngCordova','starter.controllers','ngRoute'])

最后对 bower 组件的引用是索引

 <script src="bower_components/angular-route/angular-route.js"></script>

提前感谢您的宝贵时间

您似乎使用了 angular ui-router,因此您需要使用 $stateParams 而不是 $routeParams