Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html ng-app="test">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.14/angular.min.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body ng-controller="MainCtrl">
  <a href="" ng-click="toggleList()">Toggle List</a>
  <h1>{{list}}</h1>
  <div ng-switch on="list">
  <ul>
    <li ng-repeat="book in {true: childBooks, false:adultBooks}[list==='childBooks']">{{book.name}}</li>
  </ul>
</body>
</html>
 
var app = angular.module('test', []);
app.controller('MainCtrl', function ($scope) {
  $scope.list = 'childBooks';
  
  $scope.childBooks = [{name: 'Dodobird'}, {name: 'Catty Red Hat'}];
  
  $scope.adultBooks = [{name: 'Little Lady'}, {name: 'Johny Doe'}];
  
  $scope.currentBooks = $scope.childBooks;
  
  $scope.toggleList = function () {
    if($scope.list === 'childBooks') {
      $scope.list = 'adultBooks';
      $scope.currentBooks = $scope.adultBooks;
    }
    else {
      $scope.list = 'childBooks';
      $scope.currentBooks = $scope.childBooks;
    }
  
  };
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers