haki
haki

Reputation: 9759

Is it possible to parse a string with scope variables angularjs ?

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

Upvotes: 2

Views: 623

Answers (1)

CD..
CD..

Reputation: 74146

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.

Upvotes: 4

Related Questions