1

I was looking for hours, and couldn't find a solution for this.

I have the following:

var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
    $scope.varName = "x";
    $scope.x = "Hello World!";
}

Now, I need to access x, but its name is in another variable, something like:

<td>{{ {{ varName }} }}</td>

Which doesn't work. Some other variations also didn't work.

Any idea if that is even possible?

2 Answers 2

1

Use a map in the controller to store such objects as,

$scope.dynaMap.x = "Hello world"

In the html code, do

<td>{{ dynaMap[varName] }}</td>

Here, i assume varName is x

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

Comments

0
app.controller('customersCtrl', function($scope, $http) {
    $scope.varName = "x";
    $scope.x = "Hello World!";
    $scope.getValueFromScopeProperty = function(propName) {
        return $scope[propName];
    };
}

and then:

<td>{{getValueFromScopeProperty(varName)}}</td>

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.