1

所以我得到:

错误:$injector:unpr
未知提供者 未知提供者:canOrganiseProvider <-

我不知道为什么,我简单地有这个端点,我已经测试过它工作正常,只是想在我导航到一条路线之前解决这个问题,在尝试解决 canOrganise 时它不起作用,任何想法为什么?

谢谢你。

跳进代码。

终点。

  [HttpGet]
        [Route("{eventCode}/isOrganiser")]
        [Audit(AuditLog.Nothing)]
        public IHttpActionResult HasOrganisationalRights([FromUri] string eventCode)
        {
            var response = Resolve<ICanManageEventOrganisationRightsOperation>().CanOrganiseEvent(new CanManageEventOrganisationRequest
            {
                EventCode = eventCode,
                CurrentUser = CurrentUser,
            });

            return CreateResponse(response, () => response.CanOrganise );
        }

角度路由:

angular.module('Events').config(['$routeProvider',
    function ($routeProvider) {
        $routeProvider
    .when('/event/:event/attendees', {
                        templateUrl: '/Content/AngularApp/Attendees/List/Template.html',
                        controller: 'AttendeesController',
                        resolve: {
                            'data': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                                return AttendeesService.getAttendees($route.current.params.event).then(function (response) {
                                    return response.data;
                                });
                            }],
                            'canManage': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                                return AttendeesService.canManage($route.current.params.event).then(function (response) {
                                    return response;
                                });
                            }],
                            'canOrganise': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                                return AttendeesService.isOrganiser($route.current.params.event).then(function (response) {
                                    return response;
                                });
                            }],
                            'grouped': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                                return false;
                            }]
                        }
                    })
}
]);

角服务

    angular.module('Events').factory('AttendeesService', ['$http', 
    function ($http) {
            return {

                getAttendee: function (eventCode, accountName) {
                    return $http.get('api/events/' + eventCode + '/attendees/' + accountName + '/');
                },

                isOrganiser: function (eventCode) {
                    return $http.get('api/events/' + eventCode + '/isOrganiser');
                },
    }

角度控制器

    angular.module('Events').controller('AttendeesController', ['$scope', '$rootScope', '$routeParams', '$location', '$filter', 'data', 'canManage', 'canOrganise',
        'grouped', 'AttendeesService', 'AttendeeAdderService', 'AttendeeDeleterService', 'TrackingService', 'WatcherAdderService', 'WatcherDeleterService',
        'GroupColorChangerService', 'DefaultSortingChangerService', 'AdminService',
        function ($scope, $rootScope, $routeParams, $location, $filter, data, canManage, canOrganise, grouped, AttendeesService, AttendeeAdderService, AttendeeDeleterService,
                TrackingService, WatcherAdderService, WatcherDeleterService, GroupColorChangerService, DefaultSortingChangerService, AdminService) {

...

  $scope.isOrganiser = canOrganise;

...
    }
]);

angular.module('Events', ['ngRoute', 'ngSanitize', 'angularModalService', 'ngTagsInput' ]);

4

2 回答 2

1

发现了我的问题,在 routing.js 文件中我有另一个指向相同控制器但不同 URL 的路由。第一次没有注意到..所以将提供者添加到正确的路线解决了我的问题。

在此处添加

.when('/event/:event/attendees', {
                templateUrl: '/Content/AngularApp/Attendees/List/Template.html',
                controller: 'AttendeesController',
                resolve: {
                    'data': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                        return AttendeesService.getAttendees($route.current.params.event).then(function (response) {
                            return response.data;
                        });
                    }],
                    'canManage': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                        return AttendeesService.canManage($route.current.params.event).then(function (response) {
                            return response;
                        });
                    }],
                    'canOrganise': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                        return AttendeesService.isOrganiser($route.current.params.event).then(function (response) {
                            return response;
                        });
                    }],
                    'grouped': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                        return false;
                    }]
                }
            })

但应该在这里添加

.when('/event/:event/attendees/grouped/:fieldId', {
                templateUrl: '/Content/AngularApp/Attendees/List/Template.html',
                controller: 'AttendeesController',
                resolve: {
                    'data': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                        return AttendeesService.getAttendeesGrouped($route.current.params.event, $route.current.params.fieldId).then(function (response) {
                            return response.data;
                        });
                    }],
                    'canManage': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                        return AttendeesService.canManage($route.current.params.event).then(function (response) {
                            return response;
                        });
                    }],
                    'canOrganise': ['$route', 'AttendeesService', function ($route, AttendeesService) {
                        return AttendeesService.isOrganiser($route.current.params.event).then(function (response) {
                            return response;
                        });
                    }],
                    'grouped': function () { return true; },
                }
            })
于 2017-05-10T09:27:15.043 回答
0

要使用 $routeProvider,您可以将 ng-route 模块包含到您的应用程序模块中:

angular.module('yourModule', ['ngRoute'])

并在您的 html 文件中添加连接脚本:

 <script src="bower_components/angular/angular.min.js"></script>
...
 <script src="bower_components/angular-route/angular-route.min.js"></script>
于 2017-05-10T08:50:33.567 回答