我的解决方法没有得到注入的服务,我遇到了一些问题。 我的代码如下所示:
(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 不会注入服务。我知道我做错了什么,但是有人可以帮我搞清楚吗?
答案 0 :(得分:0)
我刚在每个方法之前添加了/* @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;
};
})();