1

So i get the:

Error: $injector:unpr
Unknown Provider Unknown provider: canOrganiseProvider <-

i cannot figure out why, i simple have this end point which i've tested it works ok, and just want to resolve this before i navigate to a route, it does not work when trying to resolve canOrganise, any ideas why?

Thank you.

Jumping into code.

The end point.

  [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 routing:

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 service

    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 controller

    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' ]);

  • 1
    it seems fine for me...I'm looking for some typo but I did not find any. Did you look at your console to see if theres something wrong before reach the resolve? this is happening only with `canOrganise`? – Elmer Dantas May 10 '17 at 08:50

2 Answers2

1

found my issue, in the routing.js file i have another route that points to same controller but different URL . did not noticed the 1st time .. so adding the provider to the correct route solved my problem.

added it here

.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;
                    }]
                }
            })

but should have added it here

.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; },
                }
            })
0

For use $routeProvider you mast include ng-route module to your app module:

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

and add connect script in your html file:

 <script src="bower_components/angular/angular.min.js"></script>
...
 <script src="bower_components/angular-route/angular-route.min.js"></script>
Sergaros
  • 821
  • 1
  • 5
  • 14
  • ah yes,, i have in another file angular.module('Events', [ 'ngRoute', 'ngSanitize', 'angularModalService', 'ngTagsInput' ]); –  May 10 '17 at 09:12