Help with factory

Hi,

I have a code that is placed inside a function:

ready(function () {
product = { price: 10.0 }

Payment.init(product);
});

PaymentFactory:

var product = {};

var Payment = {
init: function§ {
product = p;
},

getPrice: function () {
return product.price;
}
}

When I call Payment.getPrice() inside a controller nothing is displayed.
What I’m doing wrong ?

Thanks.

Probably because the product in your function is out of scope when you try to call it. What you’re doing in your factory is copying the reference to the product in the factory. If you change the init function like the below it should work:

init: function(p) {
 product.price = p.price;
}

Hi
Doesn’t work
When I call getPrice() nothing is displayed.
Something wrong in my code ?

Maybe, Can you post the code of your entire factory?