angularjs - Ng-repeat doesn't works with localStorage -


something weird happening localstorage. data saved in localstorage never displayed in ng-repeat. however, when data less 2 items, in case, displayed on screen. when greater 2 not shown. controller code

$scope.saved = localstorage.getitem('todos');  if($scope.saved != null ) {     $scope.invoice = { items: json.parse($scope.saved) }; } else {     $scope.invoice = { `enter code here`         items : [{         qty: 10,         description: 'item',         cost: 9.95}]     }; } 

and addition code:

$scope.additem = function(x) {     $scope.invoice.push({         qty: 1,         description: x.cakename,         cost: x.id     });     localstorage.clear();     localstorage.setitem('todos', json.stringify($scope.invoice)); }; 

this table code:

<div>     <table class="table" style="margin-top:50px">         <tr>             <th>name</th>             <th>qty</th>             <th>cost</th>             <th>total</th>             <th></th>         </tr>         <tr ng-repeat="item in invoice">             <th>@{{ item.description }}</th>             <th>@{{ item.qty }}</th>             <th>@{{ item.cost }}</th>             <th>@{{ item.qty * item.cost }}</th>             <td>[<a href ng:click="removeitem($index)">x</a>]</td>         </tr>         <tr>             <td></td>             <td></td>             <td>total:</td>             <td> @{{ total() | currency }} </td>         </tr>     </table>      <a href="#/checkout" class="btn btn-danger">         checkout <span class="glyphicon glyphicon-shopping-cart" aria-hidden="true"></span>     </a> </div> 

when there 2 items , refresh, screen shows,

name          qty    cost   total    black forest   1      1      1    [x] berry          1      2      2    [x]           total:    $3.00 checkout  

otherwise, shows

name    qty cost    total    total:  $7.00 

as total 7.. data still there not getting displayed.

you stringify entire invoice object, when read local storage, parse object different structure.

try $scope.invoice = json.parse($scope.saved) instead.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -