jamesdeath123 jamesdeath123 - 10 months ago 43
AngularJS Question

angular how to let html redner the scope variable as a string

Say I have the following line in a controller hmmCtrl:

$rootScope.value = 1;
$scope.hmm = "{{$root.value}}"

And in html, if I have:

<section ng-controller="hmmCtrl">

Currently it displays:


but I actually want to see the value of $root.value:


In the long run I plan to put the $root.value in a json file that is going to be parsed by the hmmCtrl.

How can I make this happen?

Answer Source

So what you can do is, you can write a inside a controller which can return your interpolation expression evaluated value


//inject `$interpolate` inside controller function before using it.
$scope.evaluateValue = function(expr){
   return $interpolate(expr)($scope);


<section ng-controller="hmmCtrl">

Other way

<section ng-controller="hmmCtrl" ng-bind="evaluateValue(hmm)">

Demo Here