lalit kumar
lalit kumar

Reputation: 163

AngularJS ng-repeat with filter - notarray error , Expected array but received:

templates.js this is controller file

.controller('TemplatesDetailsCtrl', ['$scope', '$routeParams', '$http', '$filter', function($scope, $routeParams, $http, $filter){
    var templateId = $routeParams.templateId;
    $http.get('json/templates.json')
        .then(function(response){
            $scope.templates = $filter('filter')(response , function(d){
                return d.id == templateId
            })[0];
            $scope.mainImage = $scope.template.images[0].name;
        });
}]);

template-details.html

<img class="img-full" src="img/{{mainImage}}">

Upvotes: 1

Views: 49

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

As the error says, filter needs to get array as an input, but you are passing an object, try response.data

 $scope.templates = $filter('filter')(response.data , function(d){
                return d.id == templateId
 })[0];

Upvotes: 1

Related Questions