2

I want to evaluate a string in the form of "my name is {{name}}" where name is present in the current scope (same way angular does for html content).

This should be simple but i haven't managed to achieve that with eval nor compile.

JSBIN example

1 Answer 1

4

Use the $interpolate service, like:

console.log("using $interpolate: " + $interpolate("'" + s + "'")(scope));

Compiles a string with markup into an interpolation function. This service is used by the HTML $compile service for data binding.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks man - I was not familiar with this service. It's exactly what i was looking for.

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.