0

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.

1
  • Question is not clear.... you can try $scope.address Commented Sep 27, 2014 at 17:29

2 Answers 2

1

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

1
  • no actual requirement is that I already have value = "$scope.address" but now I want to fetch the value2 which is the actual value of $scope.address through "value"
    – nirajkumar
    Commented Sep 27, 2014 at 17:47
0

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];
4
  • no actual requirement is that I already have value = "$scope.address" but now I want to fetch the value2 which is the actual value of $scope.address through "value"
    – nirajkumar
    Commented Sep 27, 2014 at 17:47
  • The above code is how you would normally reference $scope
    – TGH
    Commented Sep 27, 2014 at 17:49
  • I agree but I want to fetch the value of $scope.address through a variable say tmp which has tmp="$scope.address" value . How to do it .
    – nirajkumar
    Commented Sep 27, 2014 at 17:51
  • Ok. You can try $scope["address"]
    – TGH
    Commented Sep 27, 2014 at 17:53

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.