Irfan Khan Irfan Khan - 1 year ago 88
AngularJS Question

Dynamic array push using $parse

I have three arrays and I want to push in array dynamically using $parse

For eg

$scope.image = [];
type = image;
var test = $parse(type);
test.assign($scope , push({id : 1}));

can I do something to make array push dynamic depending on type value or there is another way??

Answer Source

You don't want to use assign; you will want to get the array, then manipulate it:

$scope.image = [];
var type = 'image';
var getter = $parse(type);
getter($scope).push({ id: 1 });
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download