user3718908x100
user3718908x100

Reputation: 8509

Repeating multidimensional array object in angular

I have an array that looks like this:

[Object{ 82893u82378237832={ id=8, no=1, type="event", name="Sample1"}}, Object{ 128129wq378237832={ id=9, no=1, type="event", name="Sample2"}} ]

Now ignoring the first part which is just a random token i want to get the array inside that. i.e. id,no,type,name and display them in an ng-repeat, how can i achieve this?

This is how i create the above array:

var obj = {};
obj[data.responseData] = {
    id: 8,
    no: 1,
    type: 'event',
    name: ''
}

$scope.items.push(obj);

Upvotes: 0

Views: 1231

Answers (1)

Amir Popovich
Amir Popovich

Reputation: 29836

Your example doesn't include an array.

Anyway here's a good example.

Use map to transform an array to another array and use ng-repeat in a similar way that I've done.

Html:

<div ng-app="app">
    <div ng-controller="ctrl"> 
        <div ng-repeat="item in myArr">
            {{item}}
        </div>
    </div>
</div>

JS:

angular.module('app', []).
controller('ctrl', function ($scope) {
    var arr = [{
        myId: '82893u82378237832',
        id: 8,
        no: 1,
        type: "event",
        name: "Sample1"
    }, {
        myId: '128129wq378237832',
        id: 9,
        no: 1,
        type: "event",
        name: "Sample2"
    }];

    // mapped the new object without myId
    $scope.myArr = arr.map(function (item) {
        return {
            id: item.id,
            no: item.no,
            type: item.type,
            name: item.name
        }
    });
});

JSFIDDLE.

Upvotes: 1

Related Questions