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" -->
1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.