Olaf Erlandsen Olaf Erlandsen - 1 year ago 61
AngularJS Question

How i can parse or evaluate string with variables in AngularJS?

Well, i have a object like to:

$scope.variable = "mike";
$scope.country = "...";
$scope.posts = [
name: 'bla bla bla',
content: 'Hello, my name is {{variable}} and i am from {{country}}'

So, how i can evaluating or parse

My idea is used it in my view like this:

<a ng-click=" variable = 'John' ">Change name here!</a>
<div ng-repeat="post in posts">


Answer Source

Create a method in your controller that allows you to run the string through $interpolate, ie

// don't forget to inject the $interpolate service

$scope.parseContent = function(template) {
    return $interpolate(template)($scope);

Then you can use



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download