javascript - ng-repeat showing json object Angular JS -


i have list of items take json file via 1 service. @ end of list button can let add every item list containing elements have clicked/add. can add same item when don't exceed number of availability of items.

i have made code creates object everytime add item, problem object build not easy iterate (i have made question regarding problem..). when rendered on view appears kind of object stringify

here part of code:

the view:

<div ng-repeat="session in sessiones">    date:  {{session.date | dateformated }} &nbsp   availability: {{session.availability}} &nbsp   <a ng-click="additem($index, event, session);" ng-show="addmore"> [add cart] </a> 

<div ng-repeat="(key, value) in cartitems">     <h1> {{value.sessions}})</h1>    </div>  

the function in controller:

$scope.additem = function(index, event, session) {   if (session.availability>0){        $scope.cartitems = $scope.cartitems || {};        $scope.cartitems[event.id] = $scope.cartitems[event.id] || {title:event.title, sessions:{}}        $scope.cartitems[event.id].sessions[session.date] =          $scope.cartitems[event.id].sessions[session.date] || {num:0}        $scope.cartitems[event.id].sessions[session.date].num++;         session.availability-=1;         console.log($scope.cartitems);     } } 

here's try on fiddle

important update---> here example ilustrates want do: same instead of repeating elements when element on list have count number of times has been added

simple cart list

i fixed it. fiddle

  • i didn't see add+ link, played until appeared.
  • i suspected trouble index, fine.
  • i noticed $scope different color in javascript, noticed assigning additem wasn't controller.

so in end moved down bottom, enclosing additem:

}); 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -