ng-repeat

Filter unique values from a JSON

橙三吉。 提交于 2019-11-27 02:20:03
问题 I am using angularjs for my page. I want to filter the values from the JSON object, So that no redundancy exists. But I didn't find any way to get the unique values from angular ng-repeat. Is there anyway to do that? Ok, Here is some description about the question. I have a JSON in this format. This JSON I am getting from a service. So we cant expect how the repeated data occure. result = [ { _id: "500004", subject: "Complete the task", date: "25 Aug, 2013" }, { _id: "500004", subject:

How to use ng-repeat with filter and $index?

送分小仙女□ 提交于 2019-11-27 00:58:48
问题 I want to use ng-repeat in Angular, while I only want to output some elements of the array. An Example: ng-repeat="item in items | filter:($index%3 == 0)" However, this does not work. Please tell me how to do this; only output exact index of elements. 回答1: In your code, filter apply on 'items' array, not on each array item, that's why it does not work as you expect. Instead, you can use ng-show (or ng-if): <ul> <li ng-repeat="item in items" ng-show="$index % 3 == 0">{{item}}</li> </ul> See:

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

落爺英雄遲暮 提交于 2019-11-26 22:40:20
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 ng-repeat expression allows filtered results to be assigned to a variable. This variable will be accessible from current scope so you can use it in same scope anyway you want: <p>Number of filtered items: {{filteredItems

AngularJS : Custom filters and ng-repeat

江枫思渺然 提交于 2019-11-26 19:34:22
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 hire</li> <li data-ng-show="result.carDetails.airCon">Air conditioning</li> <li data-ng-show="result.carDetails

How to generates dynamically ng-model=“my_{{$index}}” with ng-repeat in AngularJS?

a 夏天 提交于 2019-11-26 17:28:38
问题 I would like to ask you if you can give me a hand on this. I have created a jsfiddle with my problem here. I need to generate dynamically some inputs with ng-model in a ng-repeater using the way ng-model="my_{{$index}}". In jsfiddle you can see that everything it's working fine until I try to generate it dynamically. The html would be: <div ng-app> <div ng-controller="MainCtrl"> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td> <select ng-model="selectedQuery" ng

Why the inputs are not working right with ng-repeat [duplicate]

扶醉桌前 提交于 2019-11-26 14:57:49
问题 This question already has an answer here: What are the nuances of scope prototypal / prototypical inheritance in AngularJS? 3 answers Could someone explain to me why I can't get the current selected radio-button in this simple example. I'm trying to generate dynamically the radio-buttons with an ng-repeat directive and get the current radio-button selected using ng-model. Like this: Template: <div ng-repeat="kind in movieKinds"> <input type="radio" name="movies" ng-value="kind" ng-model=

What is `priority` of ng-repeat directive can you change it?

房东的猫 提交于 2019-11-26 13:29:08
问题 Angular Documentation says: - The compilation of the DOM is performed by the call to the $compile() method. The method traverses the DOM and matches the directives. If a match is found it is added to the list of directives associated with the given DOM element. Once all directives for a given DOM element have been identified they are sorted by priority and their compile() functions are executed. The ng-repeat directive I believe has a lower priority than custom directives, in certain use

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

懵懂的女人 提交于 2019-11-26 11:45:40
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-repeat="r in data| orderBy:sort:direction"> <p>{{r.name}}</p> </div> also tried with: <div ng-repeat-start="r in data| orderBy

Custom sort function in ng-repeat

一曲冷凌霜 提交于 2019-11-26 11:43:44
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 function? <div ng-controller="aggViewport" > <div class="btn-group" > <button ng-click="setOption(opt.name)" ng

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

删除回忆录丶 提交于 2019-11-26 11:19:16
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}}">{{menuItem.name}}</a> </li> </div> app.js userApp.filter('matchAccessLevel', function() { return function(