Help with factory


I have a code that is placed inside a function:

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



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 ?


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;

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?