I know this has been answered previously, but none of those solutions are working for me. Can some one please help me with the error below?
I am getting an error using Ng-Repeat with Custom filters when I am not getting an Array.
Can anyone help me to comeup with controller to use ng-repeat which will handle for both JSONObject and JSONArray
HTML Code
<td class="features" ng-show="list.Body.WorkOrder.OrderStatus.length > 0">
<span ng-repeat="indi in list.Body.Services.ServiceChanges.ServiceDisconnects.Service | filterWithOr:{_serviceID:['SS001','ST099','SS018']} ">{{indi._serviceID}},{{indi.EPCServiceDef.EPCProduct._pn}}<br></span>
</td>
Error Will Produce when I have ServiceDisconnects section as below
"ServiceDisconnects": {
"Service": {
"-serviceID": "ST099",
"ServiceChangeActivity": "Disconnect",
"TelephoneNumbers": {
"TN": " "
},
"Rate": "0.00",
"Desc": "Xhnoecosvr",
"Count": "0",
"LOB": "Other",
"PackageCode": "ST099 ",
"EPCServiceDef": {
"EPCProduct": {
"-pn": "10400138",
"Name": "EcoSaver Opt-Out Tracking",
"LongDescription": "NO ECOSAVER TRACKING",
"Type": "Feature",
"LOB": "Video"
}
},
"CSGServiceIdentifier": "5"
}
}
But the same thing will work when the ServiceDisconnects section has multiple Service Arrays.
Here is the Custom Filter
app.filter('filterWithOr', function($filter) {
var comparator = function(actual, expected) {
if (angular.isUndefined(actual)) {
// No substring matching against `undefined`
return false;
}
if ((actual === null) || (expected === null)) {
// No substring matching against `null`; only match against `null`
return actual === expected;
}
if ((angular.isObject(expected) && !angular.isArray(expected)) || (angular.isObject(actual) && !hasCustomToString(actual))) {
// Should not compare primitives against objects, unless they have custom `toString` method
return false;
}
actual = angular.lowercase('' + actual);
if (angular.isArray(expected)) {
var match = false;
expected.forEach(function(e) {
e = angular.lowercase('' + e);
if (actual.indexOf(e) !== -1) {
match = true;
}
});
return match;
} else {
expected = angular.lowercase('' + expected);
return actual.indexOf(expected) !== -1;
}
};
return function(campaigns, filters) {
return $filter('filter')(campaigns, filters, comparator);
};
});