ui-router 中的 ng-annotate 和 resolve 方法

ng-annotate and resolve methods in ui-router

我的解析方法没有得到他们的注入服务时遇到了一些问题。 我的代码如下所示:

(function () {
    'use strict';

    angular.module('sapphire.sample-limits').config(routes);

    function routes($stateProvider) {

        console.log('sample limit routes have loaded');

        $stateProvider
            .state('sample-limits', list())
            .state('sample-limits.summary', summary())
            .state('sample-limits.summary.settings', settings())
            .state('sample-limits.summary.references', references());

        //////////////////////////////////////////////////

        function list() {
            console.log('trying to load the list sample limit route');

            return {
                url: '/sample-limits',
                templateUrl: 'app/sample-limits/sample-limits.html',
                controller: 'SampleLimitController',
                controllerAs: 'controller',
                resolve: {
                    categories: categories
                },
                data: {
                    claims: ['Sampling'],
                    pageTitle: 'Sample limits'
                }
            };
        };

        function summary() {
            return {
                url: '/{category}',
                templateUrl: 'app/sample-limits/sample-limits-summary.html',
                controller: 'SampleLimitSummaryController',
                controllerAs: 'controller',
                resolve: {
                    activate: activate
                },
                data: {
                    claims: ['Sampling'],
                    pageTitle: 'Sample limits - Summary'
                }
            };
        };

        function settings() {
            return {
                url: '/settings',
                views: {
                    '@sample-limits': {
                        templateUrl: 'app/sample-limits/sample-limits-settings.html',
                        controller: 'SampleLimitSettingsController',
                        controllerAs: 'controller'
                    }
                },
                resolve: {
                    activate: activate
                },
                data: {
                    claims: ['Sampling'],
                    pageTitle: 'Sample limits - Settings'
                }
            };
        };

        function references() {
            return {
                url: '/references/{reference}',
                views: {
                    '@sample-limits': {
                        templateUrl: 'app/sample-limits/sample-limits-references.html',
                        controller: 'SampleLimitReferencesController',
                        controllerAs: 'controller'
                    }
                },
                resolve: {
                    activate: activate
                },
                data: {
                    claims: ['Sampling'],
                    pageTitle: 'Sample limits - Groups'
                }
            };
        };

        //////////////////////////////////////////////////

        function categories(sampleLimitsService) {
            return sampleLimitsService.list();
        };

        function activate($stateParams, categories, selections) {
            categories.forEach(function (category) {
                if (category === $stateParams.category) {
                    if (selections.selected.indexOf(category) === -1) {
                        selections.select(null, category);
                    }
                }
            });
            return true;
        };
    };
})();

但是 ng-annotate 没有注入服务。我知道我做错了什么,但有人能帮我弄清楚是什么吗?

我刚刚在每个方法之前添加了 /* @ngInject */ 注释并且它起作用了:

(function () {
    'use strict';

    angular.module('sapphire.sample-limits').config(routes);

    function routes($stateProvider) {

        $stateProvider
            .state('sample-limits', list())
            .state('sample-limits.summary', summary())
            .state('sample-limits.summary.settings', settings())
            .state('sample-limits.summary.references', references());

        //////////////////////////////////////////////////

        function list() {            
            return {
                url: '/sample-limits',
                templateUrl: 'app/sample-limits/sample-limits.html',
                controller: 'SampleLimitController',
                controllerAs: 'controller',
                resolve: {
                    categories: categories
                },
                data: {
                    claims: ['Sampling'],
                    pageTitle: 'Sample limits'
                }
            };
        };

        function summary() {
            return {
                url: '/{category}',
                templateUrl: 'app/sample-limits/sample-limits-summary.html',
                controller: 'SampleLimitSummaryController',
                controllerAs: 'controller',
                resolve: {
                    activate: activate
                },
                data: {
                    claims: ['Sampling'],
                    pageTitle: 'Sample limits - Summary'
                }
            };
        };

        function settings() {
            return {
                url: '/settings',
                views: {
                    '@sample-limits': {
                        templateUrl: 'app/sample-limits/sample-limits-settings.html',
                        controller: 'SampleLimitSettingsController',
                        controllerAs: 'controller'
                    }
                },
                resolve: {
                    activate: activate
                },
                data: {
                    claims: ['Sampling'],
                    pageTitle: 'Sample limits - Settings'
                }
            };
        };

        function references() {
            return {
                url: '/references/{reference}',
                views: {
                    '@sample-limits': {
                        templateUrl: 'app/sample-limits/sample-limits-references.html',
                        controller: 'SampleLimitReferencesController',
                        controllerAs: 'controller'
                    }
                },
                resolve: {
                    activate: activate
                },
                data: {
                    claims: ['Sampling'],
                    pageTitle: 'Sample limits - Groups'
                }
            };
        };
    };

    //////////////////////////////////////////////////

    /* @ngInject */
    function categories(sampleLimitsService) {
        return sampleLimitsService.list();
    };

    /* @ngInject */
    function activate($stateParams, categories, selections) {
        categories.forEach(function (category) {
            if (category === $stateParams.category) {
                if (selections.selected.indexOf(category) === -1) {
                    selections.select(null, category);
                }
            }
        });
        return true;
    };
})();