1

I am so annoyed with AngularJS ! I've designed my modules using the following syntax:

angular.module('myModule.controllers').controller('someCtrl',
['$scope', '$route', 'someService', function ($scope, $route, someService) {
      someService.getData.success(function(){});
}

And everything used to work fine... until yesterday when I realized that I needed to use resolve in my routes so that I can delay the rendering of my views until all data is returned from my datacontext service and all promised are resolved.

However, that means I have to change the syntax above to:

function someCtrl($scope, $route, someService) {

}
someCtrl.resolve = {
  //   get data from here
 }

 someCtrl.$inject =  ['$scope', '$route', 'someService'];

So that in my route definition I can do:

controller: someCtrl,
resolve: someCtrl.resolve

I don't like the above syntax. I much preferred what I used to do (the minification-friendly syntax).

Now the problem is, using the new syntax, how do I assign someCtrl to the angular module 'myModule.controllers' that I had defined before ?

1 Answer 1

1

I know one way to handle pls see below code i have implemented in my project Note:If you use module registered controller you have to use literal notation '' with controller name

-->route

 $routeProvider.when('/Rally/:date/:id/:month', {
        templateUrl: '/partials/RallyDetail.html', controller: 'rallydetailcontroller', resolve: {
            rallydata: ['$http', '$route', function ($http, $route) {
                return $http({
                    method: 'GET',
                    url: 'https://api.mongolab.com/api/1/databases/benisoftlabs/collections/RallyDetail?q={"Candidate":"' + $route.current.params.id + '","Month":"' + $route.current.params.month + '","Date":"' + $route.current.params.date + '"}&apiKey=50920bb9e4b010d72c561d8a'
                });
            }],

        }
    });

-->controller

App.controller('rallydetailcontroller',['$scope', 'rallydata', function ($scope, rallydata) {
    $scope.rallyData = rallydata.data;
}]);
Sign up to request clarification or add additional context in comments.

1 Comment

ok, that's a start. The problem is that now, there is code in the route definition ! My routes are defined in the app.js file and I'm going to have many routes, with possibly many resolve statements. That would be one hell of a mess if I have to make call to services from there ! Any other ideas ? :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.