Angular filter exactly on object key

In Angular 1.1.3 or newer you can use the following: <div ng-repeat=”user in users | filter:{‘id’: 1}:true”> {‘id’: 1} says to only compare with the field id. That gets you: simon, 1 archie, 14 :true says “exact match” resulting in: simon, 1 Here’s that working: http://jsfiddle.net/AM95H/ To filter against a list of values, if you … Read more

How do I only show an element if nested ng-repeat is not empty?

I ended up with the following solution which worked perfectly. Plnkr By setting a variable in the inner ng-repeat I was able to evaluate ng-show based on this variables length like so : <input ng-model=”searchText”/> <span ng-show=’filtered.length > 0′> <ul> <li ng-repeat=”el in filtered = (model | filter:searchText)”> <div>{{el.label}}</div> </li> </ul> </span>

AngularJs Remove duplicate elements in ng-repeat

Just create a filter that gets the unique values, probably by a key. Something like this ought to do (I didn’t test this at all, so I’ll leave that business to you, this is just to give you an idea): app.filter(‘unique’, function() { return function(collection, keyname) { var output = [], keys = []; angular.forEach(collection, … Read more

$index of ngRepeat inside angularjs directive

Instead of scope.$parent.$index you might consider passing $index as a directive attribute: <li my-directive index=”{{$index}}” ng-repeat=”value in values”> Directive: myApp.directive(‘myDirective’, function() { return { replace: true, // transclude: true, scope: { index: ‘@’ }, template: ‘<div>testing {{index}}</div>’, link: function(scope, element, attrs) { // … } } }); Fiddle.

AngularJS – Format Text Return From JSON To Title Case

A filter is an ideal solution for this purpose <div ng-repeat=”name in FootballClubs”> {{ name.CompanyName | titleCase }} </div> So the filter itself would be angular.module(‘myFootballModule’, []) .filter(‘titleCase’, function() { return function(input) { input = input || ”; return input.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); }; })

How to achieve pagination/table layout with Angular.js?

I would use table and implement the pagination in the controller to control how much is shown and buttons to move to the next page. This Fiddle might help you. <table class=”table table-striped table-condensed table-hover”> <thead> <tr> <th class=”id”>Id&nbsp;<a ng-click=”sort_by(‘id’)”><i class=”icon-sort”></i></a></th> <th class=”name”>Name&nbsp;<a ng-click=”sort_by(‘name’)”><i class=”icon-sort”></i></a></th> <th class=”description”>Description&nbsp;<a ng-click=”sort_by(‘description’)”><i class=”icon-sort”></i></a></th> <th class=”field3″>Field 3&nbsp;<a ng-click=”sort_by(‘field3’)”><i class=”icon-sort”></i></a></th> <th … Read more

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

Yes, you can set the priority of a directive. ng-repeat has a priority of 1000, which is actually higher than custom directives (default priority is 0). You can use this number as a guide for how to set your own priority on your directives in relation to it. angular.module(‘x’).directive(‘customPriority’, function() { return { priority: 1001, … Read more

AngularJS ‘ng-filter’ is very slow on array of ~1000 elements

The main problem with the filter approach is that upon each change the dom is manipulated, so it’s not the filter that’s slow but the consequences. An alternative is to use something like: ng-show=”([item] | filter:searchFilter).length > 0″ on the repeated element. Lending some code from @OverZealous, you can use the following to compare the … Read more

AngularJS : ng-repeat filter when value is greater than

Create a predicate function on the relevant scope: $scope.greaterThan = function(prop, val){ return function(item){ return item[prop] > val; } } As a first argument, it takes a property name on the object. The second argument is an integer value. Use it in your view like this: <tr ng-repeat-start=”list in Data.Items | filter: greaterThan(‘NumberOfStamps’, 0)”> Demo

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)