<div ng-init="loadImage('/image/load/', event.listfile)"></div> 

In the event.listfile :

 [ {id: 797, filename: "image1.jpg"}, {id: 800, filename: "image12.jpg"}, {id: 798, filename: "image47.jpg"} ] 

Controller:

  $scope.loadImage = function(path, name) { $scope.image = []; name.forEach(function (element, index) { $scope.image.push({"filename": path +name[index]}); }); console.log('image: ', $scope.image); } 

Why the controller returns to the console instead of file names [object Object] :

 /image/load/[object Object] /image/load/[object Object] /image/load/[object Object] 
  • What is the relationship between the code provided and /image/load/[object Object] ? - Grundy

1 answer 1

First, name[index] is equivalent to element in your code.

Secondly, the result is logical, since the element of the name array is an object. If you need a field of this object, the field and you must choose.

As a result, the code may look like this:

 $scope.image.push({"filename": path + element.filename}); 

In addition, this implementation of the map function can be replaced by a call to the native function:

 $scope.loadImage = function(path, name) { $scope.image = name.map(el=>({"filename": path +el.filename})); console.log('image: ', $scope.image); } 
  • Names have become displayed. Thank! - Valery Orlov