首页 > 解决方案 > How to return forEach in AngularJS?

问题描述

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.

标签: angularjs

解决方案


没有办法停止或中断 forEach(),你必须使用 for 循环,如果你想使用 foreach,请像 >>>

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

并在 img 标签中使用 ng-src={{item.src}}


推荐阅读