123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <html>

<head>
  <script src="https://code.jquery.com/jquery.min.js"></script>
  <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.0/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>

<body ng-app="myApp" ng-controller="myCtrl">
  <div class="container">
    <div class="page-header">
      <h2>Nested ng-repeat in AngularJS with Checkboxes</h2>
      <p>
        Example of how to render data in nested ng-repeat(s) and get the selected items from the nested list in real-time through a change event or looping through the data in the end.
      </p>
    </div>
    <div style="font-size:larger">
      <div ng-repeat="week in myData">
        <div ng-repeat="day in week.days">
          {{day.templateDay}}
          <b>Jobs:</b>
          <br/>
          <ul>
            <li ng-repeat="job in day.jobs">
              <!-- add ng-change to get realtime updates -->
              <input type="checkbox" ng-model="job.checked" ng-change="getSelectedItems()"> {{job.name}}
            </li>
          </ul>
        </div>
        <div>
          <!-- add button to get changes at the end -->
          <p>&nbsp</p>
          <button class="btn btn-primary" ng-click="getSelectedItems($event)">
            Get Selected Items
          </button>
          <p>&nbsp</p>
          <p>
            Click below to have application update selected items in realtime
            <p>
              <input type="checkbox" ng-model="update.realtime"> Toggle Update on Change Event
              <p>&nbsp</p>
        </div>
      </div>
    </div>
    <div>
      <h4>Selected Items</h4>
      <pre class="small">{{selectedData |json}}</pre>
      <h4>Source Data</h4>
      <pre class="small">{{myData |json}}</pre>
    </div>
  </div>
</body>

</html>
            
          
!
            
              var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {

  $scope.update = {realtime : false};
  $scope.myData = [{
    "number": "2013-W45",
    "days": [{
      "templateDay": "Monday",
      "jobs": [{
        "name": "Wakeup",
      }, {
        "name": "work 9-5",

      }]
    }, {
      "templateDay": "Tuesday",
      "jobs": [{
        "name": "sleep in"
      }, {
        "name": "drop reina"
      }, {
        "name": "teach at howard"
      }]
    }]
  }];

  $scope.getSelectedItems = function(_event) {
    var data = $scope.myData;
    var results = [];
    var day = null;
    
    if (!_event && !$scope.update.realtime) {
      return
    }
    
    angular.forEach(data,function(_week){
      angular.forEach(_week.days,function(_day){
        day = _day;
        angular.forEach(_day.jobs,function(_job){
          if (_job.checked === true) {
            _job.day = day.templateDay;
            results.push(angular.copy(_job));
          }
        });
      });
    });

    $scope.selectedData = results;
  }
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console