Guest User

Untitled

a guest
Nov 23rd, 2017
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. <div class="idea item" ng-repeat="item in items" isoatom>
  2. <div class="section comment clearfix" ng-repeat="comment in item.comments | range:1:2">
  3. ....
  4. </div>
  5. </div>
  6.  
  7. myapp.filter('range', function() {
  8. return function(input, min, max) {
  9. min = parseInt(min); //Make string input int
  10. max = parseInt(max);
  11. for (var i=min; i<max; i++)
  12. input.push(i);
  13. return input;
  14. };
  15. });
  16.  
  17. // This code throws the error "Duplicates in a repeater are not allowed.
  18. // Repeater: row in [1,1,1] key: number:1"
  19. <div ng-repeat="row in [1,1,1]">
  20.  
  21. // This will work
  22. <div ng-repeat="row in [1,1,1] track by $index">
  23.  
  24. $scope.customers = JSON.parse(data)
  25.  
  26. <div ng-app="manyminds" ng-controller="MainCtrl">
  27. <div class="idea item" ng-repeat="item in items" isoatom>
  28. Item {{$index}}
  29. <div class="section comment clearfix" ng-repeat="comment in item.comments | range:1:2">
  30. Comment {{$index}}
  31. {{comment}}
  32. </div>
  33. </div>
  34. </div>
  35.  
  36. angular.module('manyminds', [], function() {}).filter('range', function() {
  37. return function(input, min, max) {
  38. var range = [];
  39. min = parseInt(min); //Make string input int
  40. max = parseInt(max);
  41. for (var i=min; i<=max; i++)
  42. input[i] && range.push(input[i]);
  43. return range;
  44. };
  45. });
  46.  
  47. function MainCtrl($scope)
  48. {
  49. $scope.items = [
  50. {
  51. comments: [
  52. 'comment 0 in item 0',
  53. 'comment 1 in item 0'
  54. ]
  55. },
  56. {
  57. comments: [
  58. 'comment 0 in item 1',
  59. 'comment 1 in item 1',
  60. 'comment 2 in item 1',
  61. 'comment 3 in item 1'
  62. ]
  63. }
  64. ];
  65. }
  66.  
  67. <div ng-repeat="product in productList.productList track by $index">
  68. <product info="product"></product>
  69. </div>
  70.  
  71. <div ng-repeat="product in productList.productList track by product.id">
  72. <product info="product"></product>
  73. </div>
  74.  
  75. <div ng-repeat="product in productList.productList track by (product.id + $index)">
  76. <product info="product"></product>
  77. </div>
  78.  
  79. {"items":
  80. &nbsp;[
  81. &nbsp;&nbsp;{
  82. "index": 1,
  83. "name": "Samantha",
  84. "rarity": "Scarborough",
  85. "email": "maureen@sykes.mk"
  86. },
  87. &nbsp;&nbsp;{
  88. "index": 2,
  89. "name": "Amanda",
  90. "rarity": "Vick",
  91. "email": "jessica@livingston.mv"
  92. }]
  93. }
  94.  
  95. <select ng-model="list_views">
  96. <option ng-selected="{{view == config.list_view}}"
  97. ng-repeat="view in list_views"
  98. value="{{view}}">
  99. {{view}}
  100. </option>
  101. </select>
  102.  
  103. <select ng-model="config.list_view">
  104. <option ng-selected="{{view == config.list_view}}"
  105. ng-repeat="view in list_views"
  106. value="{{view}}">
  107. {{view}}
  108. </option>
  109. </select>
  110.  
  111. Repeater: {0}, Duplicate key: {1}, Duplicate value: {2}
  112.  
  113. <!DOCTYPE html>
  114. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  115. <head>
  116. <meta charset="utf-8" />
  117. <title></title>
  118. <script src="angular.js"></script>
  119.  
  120. </head>
  121. <body>
  122. <div ng-app="myApp" ng-controller="personController">
  123. <table>
  124. <tr> <th>First Name</th> <th>Last Name</th> </tr>
  125. <tr ng-repeat="person in people track by $index">
  126. <td>{{person.firstName}}</td>
  127. <td>{{person.lastName}}</td>
  128. <td><input type="button" value="Select" ng-click="showDetails($index)" /></td>
  129. </tr>
  130.  
  131. </table> <hr />
  132. <table>
  133. <tr ng-repeat="person1 in items track by $index">
  134. <td>{{person1.firstName}}</td>
  135. <td>{{person1.lastName}}</td>
  136. </tr>
  137. </table>
  138. <span> {{sayHello()}}</span>
  139. </div>
  140. <script> var myApp = angular.module("myApp", []);
  141. myApp.controller("personController", ['$scope', function ($scope)
  142. {
  143. $scope.people = [{ firstName: "F1", lastName: "L1" },
  144. { firstName: "F2", lastName: "L2" },
  145. { firstName: "F3", lastName: "L3" },
  146. { firstName: "F4", lastName: "L4" },
  147. { firstName: "F5", lastName: "L5" }]
  148. $scope.items = [];
  149. $scope.selectedPerson = $scope.people[0];
  150. $scope.showDetails = function (ind)
  151. {
  152. $scope.selectedPerson = $scope.people[ind];
  153. $scope.items.push($scope.selectedPerson);
  154. }
  155. $scope.sayHello = function ()
  156. {
  157. return $scope.items.firstName;
  158. }
  159. }]) </script>
  160. </body>
  161. </html>
  162.  
  163. $http({
  164. method: 'GET',
  165. url: url, // your remote url
  166. responseType: "json"
  167. }).
  168. then(function successCallback(response) {
  169. //your code when success
  170. }, function errorCallback(response) {
  171. //your code when fails
  172. });
  173.  
  174. <li ng-repeat='name in stafflist track by $index'>{{name}}</li>
Add Comment
Please, Sign In to add comment