diff --git a/docs/content/error/filter/notarray.ngdoc b/docs/content/error/filter/notarray.ngdoc index c46befba598c..4586424de118 100644 --- a/docs/content/error/filter/notarray.ngdoc +++ b/docs/content/error/filter/notarray.ngdoc @@ -3,6 +3,49 @@ @fullName Not an array @description -This error occurs when {@link ng.filter filter} is not used with an array. +This error occurs when {@link ng.filter filter} is not used with an array: +```html + +
+ {{ key }} : {{ value }} +
+``` + Filter must be used with an array so a subset of items can be returned. -The array can be initialized asynchronously so null or undefined won't throw this error. +The array can be initialized asynchronously and therefore null or undefined won't throw this error. + +To filter an object by the value of its properties you can create your own custom filter: +```js +angular.module('customFilter',[]) + .filter('custom', function() { + return function(input, search) { + if (!input) return input; + if (!search) return input; + var expected = ('' + search).toLowerCase(); + var result = {}; + angular.forEach(input, function(value, key) { + var actual = ('' + value).toLowerCase(); + if (actual.indexOf(expected) !== -1) { + result[key] = value; + } + }); + return result; + } + }); +``` +That can be used as: +```html + +
+ {{ key }} : {{ value }} +
+``` + +You could as well convert the object to an array using a filter such as +[toArrayFilter](https://github.com/petebacondarwin/angular-toArrayFilter): +```html + +
+ {{ item }} +
+```