javascript - Adding a new input field within ng-repeat -
http://jsfiddle.net/yhv9bjrx/2/
in fiddle above, i'm trying let users add new open time when hit new item button. problem i'm having when button clicked, updates both events in ng-repeat, instead of current event on.
<ul> <li ng-repeat="event in orgevents"> <h3>event id: {{event.campaigneventid}}</h3> <h2>event name: {{event.name}}</h2> <ul> <li ng-repeat="time in orgeventtimes"> <div ng-if="time.campaigneventid == 1"> event id: <input type="text" ng-model="time.campaigneventid"> open: <input type="text" ng-model="time.opentime"> </div> </li> <button ng-click="add(item)">new item</button> </ul> <hr/> </li> </ul>
also reason ng-if statement not working, , showing every event in $scope.orgeventtimes array, instead of ones belong event.
https://jsfiddle.net/3aqwng8o/
i don't know why ng-if
isn't working.. instead of using ng-if
why not use filter
?
<li ng-repeat="time in orgeventtimes|filter: {campaigneventid:event.campaigneventid}">
your button add item pushing empty object orgeventtimes array. have push object includes campaigneventid of event instance of ng-repeat
loop.
$scope.add = function (item) { $scope.orgeventtimes.push(item); };
<button ng-click="add({campaigneventid: event.campaigneventid})">new item</button>
Comments
Post a Comment