Prageeth godage
Prageeth godage

Reputation: 4544

application level component property change

I need to change the layout componet value from page level template.

enter image description here

like in picture x.hbs may vary according to route.each spesific route may have add to cart button and when add to cart button click the layout component price should be updated.

how to do something like this in emberjs way?

Upvotes: 0

Views: 48

Answers (1)

Lux
Lux

Reputation: 18240

To manage global state you should use an service.

However for you use-case I would just rely on the store-Service provided by ember-data. You probably should create a model for your shopping-cart-items. Then you can do something like store.findAll('shopping-cart-item') in your application routes model hook. In the application controller you can get the sum with a simple Computed Property. Now if you add items to your cart, ember-data will keep everything in sync.

Maybe checkout this twiddle for demonstration.

Upvotes: 1

Related Questions