1

Let's say I have a directive myDirective. That directive wants to have an array of tag names tags, like for example ['new', 'owner']. This array is generated on the fly like;

<my-directive ng-repeat="that in a" tags="getTags(that.id)"></my-directive>

angular.module('x').directive(...
  scope: {
   tags: '@'
  }
};

Where getTags is a function that returns an array of tags.

Like this, tags will just become a string "getTags(that.id)". If I put it in an expression like;

<my-directive ng-repeat="that in a" tags="{{getTags(that.id)}}"></my-directive>

tags will still be a string. But it will look like "['new', 'owner']" - but still a string. How do I pass the array?

1 Answer 1

3

You need to parse the variable:

scope.tags = scope.$eval(scope.tags);
Sign up to request clarification or add additional context in comments.

3 Comments

I can't seem to override the scope.tags variable by doing like this?
Try in a different variable then.
Hello i had the same problem and using $eval solved it, can you please explain me why i should use $eval and if there is a better way to achieve the same thing without the use of $eval?

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.