【问题标题】:angular js getting error using $stateParams角度 js 使用 $stateParams 出错
【发布时间】:2018-07-03 19:28:06
【问题描述】:

我的应用程序运行正常,但是我在控制器中添加 $stateParams 后立即收到此错误:

angular.js:14791 Error: [$injector:unpr] Unknown provider: $stateParamsProvider <- $stateParams <- ClienteViniCtrl

来自:app.js

     .when('/clienti/:id_cliente', {
    templateUrl: 'views/cliente-vini.html',
    controller: 'ClienteViniCtrl'
  })

来自:controller.js

  .controller('ClienteViniCtrl', function($scope, $stateParams, Vini){
  Vini.getWines($stateParams.id_cliente).then(function (result) {
      $scope.vini = result;
  })

有什么问题?

【问题讨论】:

  • 在 $stateParams 之前添加 $state
  • 它们与ui.router而不是ngRoute一起使用,改为$routeParams
  • 谢谢这解决了我的问题! @AlekseySolovey

标签: angularjs angular-ui-router angularjs-injector


【解决方案1】:

您是否在项目中添加了 angular-ui-router.js?

var myApp = angular.module('myApp', ['ui.router']);

【讨论】:

  • 他的配置有.when( 而不是.state(,所以它是ngRoute
猜你喜欢
  • 1970-01-01
  • 2018-02-06
  • 2016-04-07
  • 1970-01-01
  • 2018-11-14
  • 1970-01-01
  • 1970-01-01
  • 2021-07-26
  • 2014-07-18
相关资源
最近更新 更多