Reputation: 4606
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">
{{hmm}}
</section>
Currently it displays:
{{$root.value}}
but I actually want to see the value of $root.value:
1
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?
Upvotes: 1
Views: 61
Reputation: 1224
Change your html-Code from
<section ng-controller="hmmCtrl">
{{hmm}}
</section>
to
<section ng-controller="hmmCtrl">
{{value}}
</section>
$scope inherites from $rootScope, meaning $scope also has the "value"-variable...
Upvotes: 0
Reputation: 136144
So what you can do is, you can write a inside a controller which can return your interpolation expression evaluated value
Code
//inject `$interpolate` inside controller function before using it.
$scope.evaluateValue = function(expr){
return $interpolate(expr)($scope);
}
Markup
<section ng-controller="hmmCtrl">
{{evaluateValue(hmm)}}
</section>
Other way
<section ng-controller="hmmCtrl" ng-bind="evaluateValue(hmm)">
</section>
Upvotes: 1