Concat is not a function

been trying to implement pull to refresh and infinite scroll to use in a list that 's populated from a json file
followed a tutorial : was helpful but i don’t know how to get past the concat error.

See the Pen zZbMvd by mohamed reda (@redamed) on CodePen.

thank you


concat is only a valid function for arrays or strings. Almost sure you try to concat an object or number. Try to log what the service is returning and check its type

yeah it s true.getting undefined related to the line.i followed the the service
items =; change it to that being fixed i still got the same concat error.
here’s what i get in the console just to give you an idea

Ok, the service is returning Object {news: Array(10)}, an Object, that contains an array (news). concat can not be applied to Objects, so you need to do something like

$scope.items = $scope.items.concat(

EDIT: Seen your codepen you posted before it would be

$scope.articles = [];

$scope.loadMore=function() {
    var page=2;
    article.getmorearticles(page).then(function(items) {

Of course $scope.articles must be initialized as an array before you concatenate it

I think you want to concat in the news array. If that is the case, you can do items =

@lucasbasquerotto @Adonai. so i made the changes.still getting the same error
scope.articles is initialized in the controller.then i used it in ng-repeat to display in a list

Can you share your full controller code?


Check if $scope.articles is an array


Must return true;

here it is with the factory andthe controller

See the Pen oZVmRE by mohamed reda (@redamed) on CodePen.

Thanks for sharing. I think I see the problem now

You call this function to get the articles.

            $scope.articles =;

when the API call finish, you overwrite your previous variable $scope.articles = [] to $scope.articles =;

but… as we have seen before is because return an Object (that not have concat function)

I think changing your article.getArticles() function to

   $scope.articles =;

will work.

Anyway add console.log(; to check exactly what is returning

1 Like

thanks for the help’s working.really appreciate it (y)

1 Like