When working with a complex JSON response in AngularJS, I encountered the need to filter a deeply nested array within the data. The challenge arose when only displaying a subset of attributes on the screen, leading to the necessity of restricting the filtering to visible values for a better user experience.
To tackle this issue, a custom filter had to be created as the default AngularJS filterFilter does not handle iterating over nested array elements effectively. While I initially implemented this solution successfully in AngularJS v1.2.28, it encountered issues during a migration to v1.4.3. The exact breaking point in versions remains unisolated at this time.
The migration guides provided no insights into the changes causing the failure, but it became apparent that the parameters passed to the filters differed between versions, resulting in discrepancies and ultimately, failures.
Snippet of ng-repeat filter expression:
<li ng-repeat="user in users | list_filter:{establishment: {id: filterText, names: [{name: filterText}], locations: [{streetAddress1: filterText, streetAddress2: filterText, city: filterText, stateProvince: filterText, postalCode: filterText}]}}">
Example structure of a single data element:
data = [{
id: 234567,
name: 'John Doe',
establishment: {
id: 067915959,
locations: [{
id: '134B030365F5204EE05400212856E994',
type: 'postal',
streetAddress1: 'P O BOX 900',
city: 'Grover',
stateProvince: 'CA',
postalCode: '902340900',
isoCountryCode: 'US',
region: 'MONROE'
}, {
id: '999B030365F4204EE05400212856E991',
type: 'postal',
streetAddress1: '2590 Atlantic Ave',
city: 'Fredricks',
stateProvince: 'VA',
postalCode: '45487',
isoCountryCode: 'US',
region: 'MONROE'
}],
names: [{
name: 'Grover Central School Dst',
type: 'PRIMARY'
}, {
name: 'Grover Central School Dst',
type: 'MARKETING'
}, {
name: 'Grover CENTRAL SCHOOL DISTRICT',
type: 'LEGAL'
}]
}
}];
Plunker Examples for Reference:
- Plunker for version 1.2.28: http://plnkr.co/edit/KD1MmNMBEhO7X2v9yK4S?p=info
- Plunker for version 1.4.3: http://plnkr.co/edit/OmPOOwRWCHuPutUtWOcC?p=info
Edit:
The issue seems linked to the alterations introduced in version 1.3.6.