我已经在我的控制器中声明了对2个服务的依赖,如下所示:
var app = angular.module('app', ['ngDropdowns']);
app.controller('InventoryCaptureCtrl',
['$scope', 'DataStoreService','VMInterfaceService',
function($scope, DataStoreService, VMInterfaceService) {..}
但是它抛弃了我 - Uncaught SyntaxError: Unexpected token function
在上面的声明中。问题是什么?
这是我的complte JS:
var app = angular.module('app', ['ngDropdowns']);
app.controller('InventoryCaptureCtrl', ['$scope', 'DataStoreService','VMInterfaceService',
function($scope, DataStoreService, VMInterfaceService) {
// By default the 'text' property will be used as the display text in the dropdown entry.
// All options that are not dividers must have a 'text' property.
// Or you can specify a different property name via the dropdown-item-label attribute.
//
// If an options object has an 'href' property set, then that dropdown entry
// will behave as a link and cannot be selected.
$scope.ddSelectOptions = [{
text: 'Option1',
iconCls: 'someicon'
}, {
text: 'Option2',
someprop: 'somevalue'
}, {
text: 'Option2',
someprop: 'somevalue'
}, {
text: 'Option2',
someprop: 'somevalue'
}, {
text: 'Option2',
someprop: 'somevalue'
}, ];
$scope.ddSelectOptionsType = [{
text: 'Option1',
iconCls: 'someicon'
}, {
text: 'Option2',
someprop: 'somevalue'
}, {
text: 'Option2',
someprop: 'somevalue'
}, {
text: 'Option2',
someprop: 'somevalue'
}, {
text: 'Option2',
someprop: 'somevalue'
}, ];
$scope.ddSelectSelected = {
"text": "Select a Category"
}; // Must be an object
$scope.ddSelectSelectedType = {
"text": "Select a Type"
}; // Must be an object
DataStoreService.initService();
$scope.items = DataStoreService.list();
console.log($scope.items);
var original = {
itemCategory:null,itemName:null,
itemPrice:null,purchaseDate:null,applianceType:null,
insStatus:null,id:null
};
$scope.newitem = angular.copy(original);
$scope.saveItem = function() {
alert("add new");
$scope.newitem.itemCategory = $scope.ddSelectSelected.text;
$scope.newitem.applianceType = $scope.ddSelectSelectedType.text;
DataStoreService.save($scope.newitem);
//$scope.newitem = {};
}
$scope.calculateScore = function(){
alert("calculateScore" + id);
VMInterfaceService.calculateScore(id);
}
$scope.delete = function(id) {
alert(id);
DataStoreService.delete(id);
if ($scope.newitem.id == id) $scope.newitem = {};
}
$scope.edit = function(id) {
$scope.newitem = angular.copy(DataStoreService.get(id));
}
}
]);
答案 0 :(得分:0)
应该是:
app.controller('InventoryCaptureCtrl',
['$scope', 'DataStoreService','VMInterfaceService',
function($scope, DataStoreService, VMInterfaceService) {..
}]); // => '}' close function, ']' close array and ')' close method call