0

I am building an AngularJS application and i need to store data which is inside the p tags into local storage. The challenge is that ng-model cannot be associated with p tags. Example

<div class="row">
    <div class="col">
        <p>{{product.ID}}</p>
        <p>{{product.title}}</p>
        <button ng-click="addItem()">Add to Cart</button>
    </div>
 </div>

I have a list products and i am displaying it through ng-repeat and i want to store the product.ID and product.title of the product whose corresponding Add to Cart button is clicked.

vkm
  • 548
  • 7
  • 23

1 Answers1

0

My simplest solution right know would be

<div class="row">
    <div class="col">
        <p>{{product.ID}}</p>
        <p>{{product.title}}</p>
        <button ng-click="addItem(product.ID, product.title)">Add to Cart</button>
    </div>
</div>

So if you iterate through your entrys, angularjs will simply replace the variables with the ID and the title.

http://plnkr.co/edit/Da42DI?p=preview

here a little example

Griessbrei
  • 29
  • 5
  • Cool! But the issue is that, you are stroing it in an array and the data wll be gone as the client refreshes the page. Thus, i need to use local storage. – vkm Sep 25 '15 at 07:58
  • Okay, i get your Point. So witch my code, you get the selection of the object, and than you could use the code from this answer: http://stackoverflow.com/questions/18247130/how-to-store-the-data-to-local-storage – Griessbrei Sep 25 '15 at 08:07
  • Great! I was wondering,if you could please help me out with one more issue – vkm Sep 25 '15 at 08:30
  • Just ask, if i am not able to, than some one else might answer your question as well. :) – Griessbrei Sep 25 '15 at 08:58