Angularjs 编译的代码没有错误,但将空对象移动到新列表
此部分已在单击时填充,但正在重新调整空对象。我希望对象在单击时移动到此处,但有些内容不完整,我无法理解Angularjs 编译的代码没有错误,但将空对象移动到新列表,angularjs,Angularjs,此部分已在单击时填充,但正在重新调整空对象。我希望对象在单击时移动到此处,但有些内容不完整,我无法理解 service.shoppingList2 = [ { name: "Milk", quantity: "2" }, { name: "Donuts", quantity: "200" },
service.shoppingList2 = [
{
name: "Milk",
quantity: "2"
},
{
name: "Donuts",
quantity: "200"
},
{
name: "Cookies",
quantity: "300"
},
{
name: "Musli",
quantity: "10"
},
{
name: "Chocolate",
quantity: "5"
}
];
您在列表中遗漏了对象名称定义的引号。在每个对象定义中添加引号,它们需要像在JSON文件中一样编写
service.bought = [];
service.remove = function(itemIndex){
service.bought.push(service.shoppingList2.splice(itemIndex,1));
}
service.getItems = function(){
return service.bought;
};
}
})();
这两种服务都没有区别。shoppingList2=[{“name”:“Milk”,“quantity”:“2”}];
service.bought = [];
service.remove = function(itemIndex){
service.bought.push(service.shoppingList2.splice(itemIndex,1));
}
service.getItems = function(){
return service.bought;
};
}
})();
service.shoppingList2 = [
{
"name": "Milk",
"quantity": "2"
}
];