ng-repeat

Angular ng-repeat add bootstrap row every 3 or 4 cols

谁都会走 提交于 2019-11-26 11:04:29
I'm looking for the right pattern to inject a bootstrap row class every each 3 columns. I need this because cols doesn't have a fixed hight (and I don't want to fix one), so it breaks my design ! Here is my code : <div ng-repeat="product in products"> <div ng-if="$index % 3 == 0" class="row"> <div class="col-sm-4" > ... </div> </div> </div> But it does only display one product in each row. What I want as final result is : <div class="row"> <div class="col-sm4"> ... </div> <div class="col-sm4"> ... </div> <div class="col-sm4"> ... </div> </div> <div class="row"> <div class="col-sm4"> ... </div>

Adding parameter to ng-click function inside ng-repeat doesn&#39;t seem to work

老子叫甜甜 提交于 2019-11-26 11:02:54
I have a simple loop with ng-repeat like this: <li ng-repeat='task in tasks'> <p> {{task.name}} <button ng-click="removeTask({{task.id}})">remove</button> </li> There is a function in the controller $scope.removeTask(taskID) . As far as I know Angular will first render the view and replace interpolated {{task.id}} with a number, and then, on click event, will evaluate ng-click string. In this case ng-click gets totally what is expected, ie: ng-click="removeTask(5)". However... it's not doing anything. Of course I can write a code to get task.id from the $tasks array or even the DOM, but this

Angular.js. How to count ng-repeat iterations which satisfy the custom filter

岁酱吖の 提交于 2019-11-26 08:24:56
问题 Here\'s my code: <div ng-show=\"?\" ng-repeat=\"item in items | notEmpty\"> </div> Filter: Kb.filter(\"notEmpty\", function(){ return function(input){ var output=[]; for(var i=0;i<input.length;i++){ if(input[i]){ output.push(input[i]); } } return output; }}); I need to show/hide repeated s according the quantity of filtered items in the loop. What is the best way to do it? Thanks 回答1: ng-repeat expression allows filtered results to be assigned to a variable. This variable will be accessible

AngularJS : Custom filters and ng-repeat

别来无恙 提交于 2019-11-26 06:59:48
问题 I\'m an AngularJS newbie and I\'m building up a small proof-of-concept car hire listings app that pulls in some JSON and renders out various bits of that data via an ng-repeat, with a couple of filters: <article data-ng-repeat=\"result in results | filter:search\" class=\"result\"> <header><h3>{{result.carType.name}}, {{result.carDetails.doors}} door, £{{result.price.value}} - {{ result.company.name }}</h3></header> <ul class=\"result-features\"> <li>{{result.carDetails.hireDuration}} day

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

Custom sort function in ng-repeat

一世执手 提交于 2019-11-26 02:32:03
问题 I have a set of tiles that display a certain number depending on which option is selected by the user. I would now like to implement a sort by whatever number is shown. The code below shows how I\'ve implemented it (by gettting/setting a value in the parent cards scope). Now, because the orderBy function takes a string, I tried to set a variable in the card scope called curOptionValue and sort by that, but it doesn\'t seem to work. So the question becomes, how to I create a custom sort

AngularJS - How to structure a custom filter with ng-repeat to return items conditionally

爷,独闯天下 提交于 2019-11-26 02:19:47
问题 I have an ng-repeat that prints list items. I want to write a custom filter so that the list item will print, only if a condition is true. I seem to have the structure wrong as it seems the variables are not getting passed through to the filter. index.php <div ng-show=\"userDetails.username\" class=\"nav\"> <p>Menu</p> <li ng-repeat=\"menuItem in menu | matchAccessLevel:$rootScope.userDetails.accessLevel:menuItem.minAccess | orderBy:\'position\' \"> <a ng-href=\"/angular-app/app/{{menuItem.id

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

ng-repeat :filter by single field

帅比萌擦擦* 提交于 2019-11-26 01:25:59
问题 I have an array of products that I\'m repeating over using ng-repeat and am using <div ng-repeat=\"product in products | filter:by_colour\"> to filter these products by colour. The filter is working but if the product name / description etc contains the colour then the product remains after the filter is applied. How do I set the filter to only apply to the colour field of my array rather than every field? 回答1: See the example on the filter page. Use an object, and set the color in the color

Angular ng-repeat Error “Duplicates in a repeater are not allowed.”

做~自己de王妃 提交于 2019-11-26 01:22:14
问题 I am defining a custom filter like so: <div class=\"idea item\" ng-repeat=\"item in items\" isoatom> <div class=\"section comment clearfix\" ng-repeat=\"comment in item.comments | range:1:2\"> .... </div> </div> As you can see the ng-repeat where the filter is being used is nested within another ng-repeat The filter is defined like this: myapp.filter(\'range\', function() { return function(input, min, max) { min = parseInt(min); //Make string input int max = parseInt(max); for (var i=min; i