Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to access ngCart.getTotalItems and ngCart.totalCost in my controller's view #97

Open
Jesus82 opened this issue Jul 17, 2017 · 2 comments

Comments

@Jesus82
Copy link

Jesus82 commented Jul 17, 2017

Hi, I would need to access ngCart.getTotalItems() and ngCart.totalCost() functions from my controller's view (in order to display some items conditionally based on the number of items added to the cart and the total cost of it). What would be the way to correctly accessing those functions? Should I create a service/factory for it?

Thanks in advance

@GaboDot
Copy link

GaboDot commented Jul 18, 2017

Hi!
For total items I used: ngCart.getTotalItems()
and for total cost just called: ngCart.totalCost() | currency

Another way could be:
var cart_items = ngCart.getCart().items;
var total = ngCart.getCart().totalCost;

Hope this helps!

@Jesus82
Copy link
Author

Jesus82 commented Jul 18, 2017

Hi, thanks for your reply. I have also used those functions when I'm inside the ng directive (for example, in the cart.html or checkout html files). The point is that I would like to use it also from outside the directive (that is, from my controller's view, but outside the parts injected by <ng-cart></ng-cart> or <ng-checkout></ng-checkout>

Did you manage to do that with the ngCart object? I don't seem to be able to access the object outside the directive, but maybe I'm doing something wrong...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants