Meteor client call to server not returning data

114 views Asked by At

I am building an an application that has a Cart. The Cart has an attribute called cartPrice which gets updated when a user adds or removes items from the cart. I want the client to call a server method to return the updated value of cartPrice whenever the user adds/removes an item and the cartPrice changes. Here is my code:

cart.js:

Template.Cart.helpers({
   cartPrice: function() {
     return ReactiveMethod.call("returnCartPrice");
   }
});

cart.html:

<p>Cart Total: ${{cartPrice}}</p>

server side method to return cart price:

returnCartPrice: function(error, result) {
    var currUser = Meteor.user();
    var result = currUser.cartPrice.toFixed(2);
    return result;
}

The problem I have is the price on the client side will only update if I refresh the page.

Can someone help?

Thank you.

0

There are 0 answers