Get dynamic scope array variable value in angularjs

Ankit Rai

I have a scope array variable which i am trying to access dynamically. Its value has been already set.

Its like this.

$scope.setp = { arr: [] };
$scope.setp.arr[0] = "sample Value";

When I am trying to access it dynamically as below I get undefined.

console.log($scope['setp.arr[0]']);

However I am able to access it directly using the following.

console.log($scope.setp.arr[0]);

The way of dynamically getting value of scope variable works fine for others but fails when the variable name contains square brackets i.e. [ ].

I followed this example but no success for scope variable containing array or square brackets [ ].

Also dynamically setting of scope array variable using $parse service works fine as in below.

var scopeVariable = $parse('setp.arr[0]');
scopeVariable.assign($scope, "new Value");
Thalaivar

This won't work console.log($scope['setp.arr[0]']); as its trying to access a property setp.arr[0]. You can access it like console.log($scope['setp']['arr'][0]);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get dynamic scope array variable value in angularjs

From Dev

Get dynamic scope variable value angularjs

From Dev

Dynamic scope variable in angularjs

From Dev

Fill angularjs scope with a dynamic array

From Dev

get echarts on click event to change value of variable attached to $scope in angularjs

From Dev

AngularJS Dynamic Template with indexed scope variable arrays

From Dev

AngularJS Dynamic Template with indexed scope variable arrays

From Dev

To get Value of $scope variable in HTML

From Dev

get dynamic array input in angularjs

From Dev

How to set default value for scope variable in angularjs

From Dev

How to set scope variable value in angularjs template

From Dev

How to set scope variable value in angularjs template

From Dev

How to update $scope variable value in AngularJs

From Dev

AngularJS Bind service array variable to controller scope

From Dev

Angularjs: accessing scope variable array and calculating average

From Dev

AngularJS Bind service array variable to controller scope

From Dev

How to get checked checkbox value and store it array variable in angularjs?

From Dev

AngularJS - Get $scope variable from string

From Dev

AngularJS - Get $scope variable from string

From Dev

get dynamic value from a variable

From Dev

loading scope value into an array doesnt work in angularjs

From Dev

Get array from dynamic variable

From Dev

Get value of checkbox into angularjs $scope object

From Dev

AngularJS Dynamic Ng Model That Goes Back To Scope Variable

From Dev

AngularJS - Dynamic scope fields

From Dev

How to get the variable value on the scope of subscribe?

From Dev

AngularJS dynamic input value binding to an array model

From Dev

AngularJS dynamic input value binding to an array model

From Dev

Angularjs get value from array

Related Related

  1. 1

    Get dynamic scope array variable value in angularjs

  2. 2

    Get dynamic scope variable value angularjs

  3. 3

    Dynamic scope variable in angularjs

  4. 4

    Fill angularjs scope with a dynamic array

  5. 5

    get echarts on click event to change value of variable attached to $scope in angularjs

  6. 6

    AngularJS Dynamic Template with indexed scope variable arrays

  7. 7

    AngularJS Dynamic Template with indexed scope variable arrays

  8. 8

    To get Value of $scope variable in HTML

  9. 9

    get dynamic array input in angularjs

  10. 10

    How to set default value for scope variable in angularjs

  11. 11

    How to set scope variable value in angularjs template

  12. 12

    How to set scope variable value in angularjs template

  13. 13

    How to update $scope variable value in AngularJs

  14. 14

    AngularJS Bind service array variable to controller scope

  15. 15

    Angularjs: accessing scope variable array and calculating average

  16. 16

    AngularJS Bind service array variable to controller scope

  17. 17

    How to get checked checkbox value and store it array variable in angularjs?

  18. 18

    AngularJS - Get $scope variable from string

  19. 19

    AngularJS - Get $scope variable from string

  20. 20

    get dynamic value from a variable

  21. 21

    loading scope value into an array doesnt work in angularjs

  22. 22

    Get array from dynamic variable

  23. 23

    Get value of checkbox into angularjs $scope object

  24. 24

    AngularJS Dynamic Ng Model That Goes Back To Scope Variable

  25. 25

    AngularJS - Dynamic scope fields

  26. 26

    How to get the variable value on the scope of subscribe?

  27. 27

    AngularJS dynamic input value binding to an array model

  28. 28

    AngularJS dynamic input value binding to an array model

  29. 29

    Angularjs get value from array

HotTag

Archive