1

http://jsfiddle.net/yhv9bjrx/2/

In the fiddle above, I'm trying to let users add a new open time when they hit the new item button. The problem I'm having is that when the button is clicked, it updates both events in the ng-repeat, instead of the current event its 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 for some reason the ng-if statement is not working, and it is showing every event in the $scope.orgEventTimes array, instead of just the ones belong to this event.

2
  • Are you bound to use the same data structure of events and it't time i.e. events in a separate list and their times in a separate list, or can you change the data structure? Commented Jun 26, 2015 at 11:13
  • @ShashankAgrawal unfortunately I'm bound to the same data structure of them both being in separate lists Commented Jun 26, 2015 at 11:33

1 Answer 1

1

https://jsfiddle.net/3aqwng8o/

I don't know why the ng-if isn't working.. Instead of using ng-if why not use a filter?

<li ng-repeat="time in orgEventTimes|filter: {CampaignEventID:event.CampaignEventID}">

Your button to add an item is simply pushing an empty object into the orgEventTimes array. Have it push an object that includes the CampaignEventID of the event for that instance of ng-repeat loop.

   $scope.add = function (item) {
          $scope.orgEventTimes.push(item);
        };

<button ng-click="add({CampaignEventID: event.CampaignEventID})">New Item</button>

Sign up to request clarification or add additional context in comments.

1 Comment

I wouldn't expose the CampaignEventID as an input either as the input will disappear if you delete it, but still remain in the array with a blank ID, but presumably this was just for testing/development purposes.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.