03.12.2015 Views

laravel4cookbook

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

E-Commerce 264<br />

24 @{{ product.total }}<br />

25 <br />

26 <br />

27 <br />

31 <br />

32 <br />

33 <br />

34 <br />

35 <br />

.<br />

This was extracted from app/views/index.blade.php.<br />

We’ve change the numeric input element to use ng-model and ng-change directives. The first tells<br />

the input which dynamic (quantity) value to bind to, and the second tells the basket what to do if<br />

the input’s value has changed. We already know that this means re-calculating the total cost of that<br />

product, and storing the products back in $cookies.<br />

We’ve also added an ng-click directive to the remove link; so that the product can be removed from<br />

the basket.<br />

.<br />

You may have noticed track by $index, in the hg-repeat directive. This is needed as ng-repeat will<br />

error when it tries to iterate over the parsed JSON value (which is stored in $cookies). I found out<br />

about this at: http://docs.angularjs.org/error/ngRepeat:dupes.<br />

We need to be able to remove the basket items, also. Let’s modify the JavaScript/HTML to allow for<br />

this:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!