Answer the question
In order to leave comments, you need to log in
How does Javascript work?
There is a basket script (written in angular, but that's not the point).
I can not understand.
vm.cartItems = [];
function addItemsList(id, name, type) {
var objItems = {
id: id,
name: name,
type: type
};
vm.cartItems.push(objItems);
}
function getItemsList() {
console.log('корзина' +vm.cartItems);
return vm.cartItems;
}
console.log('корзина' +vm.cartItems);
shows nothing. Only "basket". Answer the question
In order to leave comments, you need to log in
try passing this vm.cartItems to the function, perhaps at the time of the function execution this object is read from the scope, where it is empty
i.e. at the time of output to the console, you are transferred (more precisely, it is not transferred, but read) an empty array, but then it is filled and you see that everything is working fine
I may be wrong, but here, in my opinion, it is necessary to use the enumeration of the object's properties using for in
. Neither the alert nor the console.log shows the contents of the object by simply calling the variable that contains it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question