Show / Hide Table of Contents
-
Error Reference
- Error Reference
- $animate
- nongcls
- notcsel
- $cacheFactory
- iid
- $compile
- baddir
- badrestrict
- ctreq
- ctxoverride
- infchng
- iscp
- missingattr
- multidir
- multilink
- noctrl
- nodomevents
- nonassign
- noslot
- reqslot
- selmulti
- srcset
- tplrt
- uterdir
- $controller
- ctrlfmt
- ctrlreg
- noscp
- $http
- baddata
- badjsonp
- badreq
- $injector
- cdep
- itkn
- modulerr
- nomod
- pget
- strictdi
- undef
- unpr
- $interpolate
- badexpr
- dupvalue
- interr
- logicbug
- nochgmustache
- noconcat
- reqarg
- reqcomma
- reqendbrace
- reqendinterp
- reqopenbrace
- reqother
- unknarg
- unsafe
- untermstr
- wantstring
- $interval
- badprom
- $location
- badpath
- ipthprfx
- isrcharg
- nobase
- nostate
- $parse
- esc
- lexerr
- lval
- syntax
- ueoe
- $q
- norslvr
- qcycle
- $resource
- badargs
- badcfg
- badmember
- badname
- $rootScope
- infdig
- inprog
- $route
- norout
- $sanitize
- elclob
- noinert
- uinput
- $sce
- icontext
- iequirks
- imatcher
- insecurl
- itype
- iwcard
- unsafe
- $templateRequest
- tpload
- $timeout
- badprom
- filter
- notarray
- jqLite
- nosel
- offargs
- onargs
- linky
- notstring
- ng
- aobj
- areq
- badname
- btstrpd
- cpi
- cpta
- cpws
- test
- ngModel
- constexpr
- datefmt
- nonassign
- nopromise
- numfmt
- ngOptions
- iexp
- ngPattern
- noregexp
- ngRef
- noctrl
- nonassign
- ngRepeat
- badident
- dupes
- iexp
- iidexp
- ngTransclude
- orphan
- orderBy
- notarray
Loading …
There was an error loading this resource. Please try again later.
Improve this Doc
Error: filter:notarray
Error: filter:notarray
Not an array
Expected array but received: {
Description
This error occurs when filter is not used with an array:
<input ng-model="search">
<div ng-repeat="(key, value) in myObj | filter:search">
{{ key }} : {{ value }}
</div>
Filter must be used with an array so a subset of items can be returned. 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:
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:
<input ng-model="search">
<div ng-repeat="(key, value) in myObj | custom:search">
{{ key }} : {{ value }}
</div>
You could as well convert the object to an array using a filter such as toArrayFilter:
<input ng-model="search">
<div ng-repeat="item in myObj | toArray:false | filter:search">
{{ item }}
</div>