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

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

1 Comment

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"
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 Comments

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"
The above code is how you would normally reference $scope
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 .
Ok. You can try $scope["address"]

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.