Passing dependencies alongside other services in ngDialog - Angular

66 views Asked by At

I'm opening a dialog which is sorting some of my elements. It has it's own controller and uses some of mutual services.

$scope.openSortDialog = function(category) {
  ngDialog.open({
    template: 'views/forms/sort.html',
    resolve: {
      category: category
    },
    controller: 'SortController',
    controllerAs: 'sort'
  });
};

I would like to keep SortController in other file as it's pretty big. But the problem is the resolve which I'm using to let SortController know which category is being sorted.

These are SortController dependencies:

.controller('SortController', function($scope, SharedService, ngDialog) {...

I have added the resolve just now as I am refactoring and have no idea how to include that dependency. What I did so far is put the category being sorted in SharedService which Sort has access to. But I'd like to have more direct route.

So the question is, how do I get resolve dependencies alongside controller dependencies.

1

There are 1 answers

0
huan feng On

I think this is what you want:

$scope.openSortDialog = function(category) {
    ngDialog.open({
        template: 'views/forms/sort.html',
        controller: 'SortController',
        controllerAs: 'sort'
        resolve: {
            category: function () {
                return category;
            }
        }
}



.controller('SortController', ['$scope', 'category', 'SharedService', 'ngDialog',
    function($scope, category, SharedService, ngDialog) {...