I am calling my Firebase Database JSON in AngularJS and trying to filter through the code. I keep seeing Array errors like:
Error: [filter:notarray] http://errors.angularjs.org/1.4.9/filter/notarray?
My HTML:
<form>
<div class="form-group">
<div class="input-group">
<div class="input-group-addon"><i class="fa fa-search"></i></div>
<input type="text" class="form-control" placeholder="Search" ng-model="searchTranslation">
</div>
</div>
</form>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>ID</th>
<th>English</th>
<th>Arabic</th>
<th>Status</th>
<th>Settings</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="i in translations | filter:searchTranslation track by $index">
<td>{{$index}}</td>
<td>{{i.transNameEn}}</td>
<td class="textarabic">{{i.transNameArabic}}</td>
<td class="{{i.transStatus}}">{{i.transStatus}}</td>
<td>
<a ng-href="{{url}}pages-edit-translation/{{i.transId}}"
class="btn caps btn-warning">
EDIT
</a>
</td>
</tr>
</tbody>
</table>
My JS code
// @pages-home-translation
cmsApp.controller('pages-home-translation', function ($scope, $http) {
$scope.sortType = 'English'; // set the default sort type
$scope.sortReverse = false; // set the default sort order
$scope.searchTranslation = ''; // set the default search/filter term
$http.get(firebase_url+'cms/translations.json'+randstatus).success(function(data) {
$scope.translations=data; // or data.data
});
});
My JSON:
{
"00hym5km2tf08s38fr-ivjgnsw6": {
"notes": "",
"transCreation": "11/15/2016, 4:14:07 PM",
"transId": "00hym5km2tf08s38fr-ivjgnsw6",
"transModified": "11/15/2016, 4:14:07 PM",
"transNameArabic": "استخدم كعنوان الدفع الافتراضي",
"transNameEn": "Use as my default billing address",
"transStatus": "FIXED"
},
"08zq3t9411zaketnpnwmi-ivjhzz5q": {
"notes": "",
"transCreation": "11/15/2016, 4:51:35 PM",
"transId": "08zq3t9411zaketnpnwmi-ivjhzz5q",
"transModified": "11/15/2016, 4:51:35 PM",
"transNameArabic": "احذية كرة القدم",
"transNameEn": "Football Shoes",
"transStatus": "FIXED"
},
"0aoycw0b0c9v8ov6xbt9-ivjhwnv6": {
"notes": "",
"transCreation": "11/15/2016, 4:49:00 PM",
"transId": "0aoycw0b0c9v8ov6xbt9-ivjhwnv6",
"transModified": "11/15/2016, 4:49:00 PM",
"transNameArabic": "جينز واسع",
"transNameEn": "Flared Jeans",
"transStatus": "FIXED"
}
}
Note: If I remove
<tr ng-repeat="i in translations | filter:searchTranslation track by $index">
and do this instead it works:
<tr ng-repeat="i in translations">
But clearly I wish to filter the results using the search form. Using data.data shows no errors in the console.
I have tried to do setTimeOut on the http.get and also delays so that it loads the JSON first but it is still not working.
Thanks
data.data, which will contain the data. The object that is passed to thesuccesscallback is theresponseobject, which amongst others contains thedataproperty, which you are after.