1

I have two dynamic variable on my templates and I want use a dynamic within another dynamic variable on angular.for clear what I want I write down a snippet to clear my aim :

My Goal results of this snippet should be "John Doe", my question is ** how can I use a variable within another variable in angular ? is there any way to achieve this?

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body>

<div ng-app="" ng-init="person={firstName:'John',var:'Doe'};dynamic='var'">

<p>The name is {{ person.{{dynamic}} }}</p>
</div>

</body>
</html>

1 Answer 1

3

Try this code

<div ng-app="" ng-init="person={firstName:'John',var:'Doe'};dynamic='var'">
  <p>The name is {{ person[dynamic] }}</p>
</div>
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.