nirajkumar
nirajkumar

Reputation: 330

Angularjs : How to find value of a variable store in a string

It seems novice question but I am not able to figure it out how to find value of a variable store in a string e.g

var value = "Scope.address";

Actually I want to find the value of "Scope.address" how to find it.

Upvotes: 0

Views: 979

Answers (2)

Gangadhar Jannu
Gangadhar Jannu

Reputation: 4414

I am not able to understand what you want.

If you want to access a variable address(in angular this might be model) you have to use $scope.address.

Here is the example

<input type="text" ng-model="address">

and the corresponding script to access address in controller is

var value=$scope.address;

Updated

var value2=$scope[value];

Here is a demo

Upvotes: 1

TGH
TGH

Reputation: 39258

You have to reference $scope from a location where $scope is available. One common location is your controller

var value = $scope.address;

If you need it to be dynamic try the following:

 var value = 'address';
 var myDynamicValue = $scope[value];

Upvotes: 0

Related Questions