gpt4 book ai didi

javascript - 在angularjs中声明多个服务依赖

转载 作者:行者123 更新时间:2023-11-28 07:45:44 25 4
gpt4 key购买 nike

我已经在我的 Controller 中声明了对 2 个服务的依赖,如下所示:

var app = angular.module('app', ['ngDropdowns']);  


app.controller('InventoryCaptureCtrl',
['$scope', 'DataStoreService','VMInterfaceService',
function($scope, DataStoreService, VMInterfaceService) {..}

但是它抛出了我 - Uncaught SyntaxError: Unexpected token function 在上面的声明中。问题是什么?

这是我的完整 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));
}
}
]);

最佳答案

应该是:

app.controller('InventoryCaptureCtrl', 
['$scope', 'DataStoreService','VMInterfaceService',
function($scope, DataStoreService, VMInterfaceService) {..

}]); // => '}' close function, ']' close array and ')' close method call

关于javascript - 在angularjs中声明多个服务依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27461006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com