Angular 1.5未知提供商

时间:2017-05-10 08:38:31

标签: angularjs angular-routing angular-providers

所以我得到了:

  

错误:$ 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' ]);

2 个答案:

答案 0 :(得分: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; },
                }
            })

答案 1 :(得分:0)

对于使用$ routeProvider,你可以使用ng-route模块到你的app模块:

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

并在html文件中添加connect脚本:

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