How to return forEach in AngularJS?

51 views Asked by At

I'm new to AngularJS and I can't fix one problem. I have value, which stores multiple numbers. I want to use the numbers as part of URL however I don't know how to make forEach loop.

this is my code:

angular.module('eOpti.app.tasks').controller('packsController', [
'$scope', '$http', '$stateParams', 'breadcrumb',
function ($scope, $http, $stateParams, breadcrumb) {
    breadcrumb.data = [{
        name: 'Pakiety'
    }];

    $scope.renderers={
        właściwości:function(value, row){
             value.forEach(value, function(val){
                return '<img src="http://192.168.1.215/img/task/pack/' + val + '.png" style=width:44px;margin-right:3px>';
                })
            }
        }


}]);

I want to create val from value but doing something wrong.

2

There are 2 answers

1
Kusy On BEST ANSWER

Thank you for reply, the problem is I'm using Laravel tableHelper so I dont have standart views to use ng-src.

However I solved it in another way. Before I tried to return URL in wrong function and was trying forEach on object, what's also not correct.

I solved it by splitting value and returned string in correct function - that way:

        $scope.renderers={
        właściwości:function(value){
            var string = '';
            value.split(',').forEach(function(val){
                string += '<img src="http://192.168.1.215/img/task/pack/' + val + '.png" style=width:44px;margin-right:3px>';
                })
                return string;
            }
        }
}]);
0
Hrishi On

There is no way to stop or break a forEach(), you have to use for loop , if you want to use foreach do it like >>>

 value.forEach(function (item) {
     item.src = 'http://192.168.1.215/img/task/pack/'+item.val+'.png'
 });

and use ng-src={{item.src}} in img tag