# Computed property of service

**URL:** <https://discuss.emberjs.com/t/computed-property-of-service/8917>\
**Category:** Ember CLI\
**Created:** [October 6, 2015, 5:03pm UTC](https://discuss.emberjs.com/t/computed-property-of-service/8917 "2015-10-06T17:03:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zasmail](https://avatars.discourse-cdn.com/v4/letter/z/b77776/32.png) [@zasmail](https://discuss.emberjs.com/u/zasmail)\
**Post date:** [October 6, 2015, 5:03pm UTC](https://discuss.emberjs.com/t/computed-property-of-service/8917/1 "2015-10-06T17:03:28Z")

</div>

Hi!

I was hoping to have a computed property off of a service object and have had trouble doing so. I have a shopping cart service and a shop route which allows customers to pick items and add them to the cart. I have no problem adding them to the cart, but when I try to add a computed property from the controller or route, they never fire when the objects (cart and cartTotal) change.

Here’s the cart service:

```
export default Ember.Service.extend({
  cart: [],
  currentTotal: 0,
addToCart(product){
    // TODO add promise here
    this.get('cart').push(product);
    this.get('updateTotal')(this);
  },

  updateTotal: function(context){
    debugger;
    var total = 0;
    context.get('cart').forEach(function(product){
      total += parseInt(product.get('price'));
    }.bind(total));
    context.set('currentTotal', total);
  },
 ...

```

And here’s my shop controller:

```
const { service } = Ember.inject;

export default Ember.Controller.extend({
  cart: service('cart'),
  products: null,
  productGroupings: null,
  menus: null,
  currentMenu: Ember.computed.oneWay('cart.currentMenu'),
  menus: Ember.computed.oneWay('cart.menus'),
  cartTotal: Ember.computed.oneWay('cart.cartTotal'),
  ...

```

It also fails with observers setting the properties as well as using alias inplace of ‘oneWay.’ This also fails on the route. I’m currently running Ember 1.13.8.

Thank you!

---

<div class="post-metadata">

**Author:** ![zasmail](https://avatars.discourse-cdn.com/v4/letter/z/b77776/32.png) [@zasmail](https://discuss.emberjs.com/u/zasmail)\
**Post date:** [October 6, 2015, 7:15pm UTC](https://discuss.emberjs.com/t/computed-property-of-service/8917/2 "2015-10-06T19:15:50Z")

</div>

Just realized that I forgot to add this.notifyPropertyDidChange around the push. Without the set, the computed properties never fired. Adding that fixed it right up.

---

<div class="post-metadata">

**Author:** ![stefan](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/stefan/32/14174_2.png) [@stefan](https://discuss.emberjs.com/u/stefan)\
**Post date:** [October 8, 2015, 3:48pm UTC](https://discuss.emberjs.com/t/computed-property-of-service/8917/3 "2015-10-08T15:48:19Z")

</div>

`push` is unobserved, you must use `pushObject`
