0
votes

I wrote a method to return a value onto the client:

Template.Cart.helpers({

  cartPrice: function(result) {
    Meteor.call('returnCartPrice', function(error, result) {
    if(error) {
      alert(error.reason);
    } else {
      alert('result is ' + result); //this alerts
      return result;
    }
    alert('result is ' + result); //this does NOT alert
    return result;
  });
 }
});

cart.html:

<p>{{cartPrice}}</p>

To test my code, i put in two alerts. The first alert correctly alerts the result. However, the second alert does not do anything. Can someone help point out what I am doing wrong?

Thank you!

2

2 Answers

1
votes

You are returning the value inside the else clause, thus the other snippet is never called. You might want to alert the error and return anyway. Just bear in mind the call is asynchronous.

0
votes

You are returning result after your first alert which stops further execution of your code inside the function, hence your second alert does not run