Irfan Khan Irfan Khan - 3 months ago 14
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

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 });