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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.