我正在开发一个包含元素列表的系统,当您选择一个元素时,您会看到该元素的详细信息。我使用的是MEAN。我想要做的是将所选元素的id传递给第二页的控制器。我试图通过使用价值和服务来实现这一点,但它给了我这个错误:
[$injector:unpr] Unknown provider: chooserIdProvider <- chooserId <- controllerIdService
http://errors.angularjs.org/1.6.5/$injector/unpr?p0=chooserIdProvider[object Object]3C-%6chooserId%6%3C-%6controllerIdService
https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.js:116
这是我的代码(我只会显示服务和值的一部分): firstController:
var streamingApp = angular.module('streaming', ['ngRoute']);
streamingApp.controller("homeController", ['$scope', '$http', '$location', function ($scope, $http, $location) {
...
$scope.process = function(chooserId) {
streamingApp.value('chooserId', chooserId);
$location.path("/indico")
}
firstWeb(使用$ scope.process的部分):
<a class="btn btn-primary" ng-click="process(chooser._id)">Process</a>
secondController:
streamingApp.service('controllerIdService', ['chooserId', function(chooserId) {
this.chooserId = chooserId;
}]);
streamingApp.controller("indicoController", ['$scope', '$http', '$location', 'controllerIdService', function ($scope, $http, $location, controllerIdService) {
this.chooserId = chooserId;
secondWeb:
<h5>{{chooserId}}</h5>
答案 0 :(得分:0)
You should access the variable like this: controllerIdService.chooserId
. And also it should be present in the scope for accessing it in the view.