1

I want to do something like this in angular how can you do this?

$scope.test = "foo"; 
$scope.foo = "bar";

and in view

<span>{{scope[test]}}</span> <!-- and return $scope.foo that is "bar" -->
dfsq
  • 191,768
  • 25
  • 236
  • 258
  • 2
    see this http://stackoverflow.com/questions/18875486/setting-dynamic-scope-variables-in-angularjs-scope-some-string – Hadi J May 21 '16 at 07:09

1 Answers1

1

It should be with bracket notation:

<span>{{this[test]}}</span>

this points to current scope object, so with variable test beeing "foo", the expression will reference $scope.foo.

dfsq
  • 191,768
  • 25
  • 236
  • 258