3

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??

4
  • What is type = image supposed to accomplish…? Commented Aug 24, 2016 at 10:08
  • var type = "image"; it should be like this and type value can take another array value like type = "video or type = "gif" Commented Aug 24, 2016 at 10:13
  • If it's only a single string, $scope[type].push(..) will do just fine. $parse really only becomes interesting if you have more complex paths (e.g. foo.bar.baz). Commented Aug 24, 2016 at 10:14
  • Can you post what you have tried and not working? Commented Aug 24, 2016 at 10:14

1 Answer 1

2

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 });
Sign up to request clarification or add additional context in comments.

1 Comment

can you please give eg. how to do that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.