angularjs-ng-repeat

passing 2 $index values within nested ng-repeat

若如初见. 提交于 2019-11-26 03:36:53
问题 So I have an ng-repeat nested within another ng-repeat in order to build a nav menu. On each <li> on the inner ng-repeat loop I set an ng-click which calls the relevant controller for that menu item by passing in the $index to let the app know which one we need. However I need to also pass in the $index from the outer ng-repeat so the app knows which section we are in as well as which tutorial. <ul ng-repeat=\"section in sections\"> <li class=\"section_title {{section.active}}\" > {{section

Difficulty with ng-model, ng-repeat, and inputs

爱⌒轻易说出口 提交于 2019-11-26 03:24:31
问题 I am trying to allow the user to edit a list of items by using ngRepeat and ngModel . (See this fiddle.) However, both approaches I\'ve tried lead to bizarre behavior: one doesn\'t update the model, and the other blurs the form on each keydown. Am I doing something wrong here? Is this not a supported use case? Here is the code from the fiddle, copied for convenience: <html ng-app> <head> <link href=\"//netdna.bootstrapcdn.com/twitter-bootstrap/2.2.1/css/bootstrap-combined.min.css\" rel=\

AngularJS For Loop with Numbers & Ranges

送分小仙女□ 提交于 2019-11-26 03:16:10
问题 Angular does provide some support for a for loop using numbers within its HTML directives: <div data-ng-repeat=\"i in [1,2,3,4,5]\"> do something </div> But if your scope variable includes a range that has a dynamic number then you will need to create an empty array each time. In the controller var range = []; for(var i=0;i<total;i++) { range.push(i); } $scope.range = range; In the HTML <div data-ng-repeat=\"i in range\"> do something </div> This works, but it is unnecessary since we won\'t

Angular ng-repeat conditional wrap items in element (group items in ng-repeat)

 ̄綄美尐妖づ 提交于 2019-11-26 02:35:22
问题 I\'m trying to group the items in a ng-repeat using a condition. An example condition is to group all elements with the same hour. The data: [ {name: \'AAA\', time: \'12:05\'}, {name: \'BBB\', time: \'12:10\'}, {name: \'CCC\', time: \'13:20\'}, {name: \'DDD\', time: \'13:30\'}, {name: \'EEE\', time: \'13:40\'}, ... ] The \'time\' field is actually a timestamp (1399372207) but with the exact time the example output is easier to understand. I am listing these items using ng-repeat: <div ng

How to improve performance of ngRepeat over a huge dataset (angular.js)?

烈酒焚心 提交于 2019-11-26 02:26:56
问题 I have a huge dataset of several thousand rows with around 10 fields each, about 2MBs of data. I need to display it in the browser. Most straightforward approach (fetch data, put it into $scope , let ng-repeat=\"\" do its job) works fine, but it freezes the browser for about half of a minute when it starts inserting nodes into DOM. How should I approach this problem? One option is to append rows to $scope incrementally and wait for ngRepeat to finish inserting one chunk into DOM before moving

ng-repeat filtering data by date range

烂漫一生 提交于 2019-11-26 02:11:21
问题 I\'m trying to filter a list that contains a timestamp by typing a range of dates for example: JSFIDDLE html <div ng-app=\"tst\"> <div ng-controller=\"MyController\"> <table> <tr> <td>From: <input ng-model=\"query.date1\" type=\"text\" placeholder=\"\" /> </td> <td>To: <input ng-model=\"query.date2\" type=\"text\" placeholder=\"\" /> </td> </tr> <tr ng-repeat=\"order in orders |filter:query\"> <td>{{order.date1 * 1000 | date:\'dd-MM-yyyy\'}}</td> <td>{{order.date2 * 1000 | date:\'dd-MM-yyyy\'

Way to ng-repeat defined number of times instead of repeating over array?

我是研究僧i 提交于 2019-11-26 01:27:36
问题 Is there a way to ng-repeat a defined number of times instead of always having to iterate over an array? For example, below I want the list item to show up 5 times assuming $scope.number equal to 5 in addition incrementing the number so each list item increments like 1, 2, 3, 4, 5 Desired result: <ul> <li><span>1</span></li> <li><span>2</span></li> <li><span>3</span></li> <li><span>4</span></li> <li><span>5</span></li> </ul> 回答1: At the moment, ng-repeat only accepts a collection as a

How to filter multiple values (OR operation) in angularJS

青春壹個敷衍的年華 提交于 2019-11-26 01:24:30
问题 I want to use the filter in angular and want to filter for multiple values, if it has either one of the values then it should be displayed. I have for example this structure: An object movie which has the property genres and I want to filter for Action and Comedy . I know I can do filter:({genres: \'Action\'} || {genres: \'Comedy\'}) , but what to do if I want to filter it dynamically. E.g. filter: variableX How do I set variableX in the $scope , when I have an array of the genres I have to

Calculating sum of repeated elements in AngularJS ng-repeat

断了今生、忘了曾经 提交于 2019-11-26 00:41:44
问题 The script below displays a shop cart using ng-repeat . For each element in the array, it shows the item name, its amount and the subtotal ( product.price * product.quantity ). What is the simplest way for calculating the total price of repeated elements? <table> <tr> <th>Product</th> <th>Quantity</th> <th>Price</th> </tr> <tr ng-repeat=\"product in cart.products\"> <td>{{product.name}}</td> <td>{{product.quantity}}</td> <td>{{product.price * product.quantity}} €</td> </tr> <tr> <td></td> <td

how to split the ng-repeat data with three columns using bootstrap

强颜欢笑 提交于 2019-11-26 00:20:13
问题 I am using ng-repeat with my code I have \'n\' number of text box based on ng-repeat. I want to align the textbox with three columns. this is my code <div class=\"control-group\" ng-repeat=\"oneExt in configAddr.ext\"> {{$index+1}}. <input type=\"text\" name=\"macAdr{{$index+1}}\" id=\"macAddress\" ng-model=\"oneExt.newValue\" value=\"\"/> </div> 回答1: The most reliable and technically correct approach is to transform the data in the controller. Here's a simple chunk function and usage.