eugene007
asked on
angular.forEach access outside variable
I intend to access the outer variable stated below
Inside the following like of code
here is the full line of code:
Your help is kindly appreciated.
Thank You.
if(key==='data'){
outer; //outer variable
}
Inside the following like of code
angular.forEach(outer.permission, function(outer_perm, key) {
//I want to access outer
});
here is the full line of code:
angular.forEach($array, function(outer, key) {
if(key==='data'){
outer;
}
if(key==='try'){
angular.forEach(outer, function(outer, key){
$module_name = outer.name;
//console.log($module_name);
angular.forEach(outer.permission, function(outer_perm, key) {
//I want to access outer
});
});
}
});
Your help is kindly appreciated.
Thank You.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Your code relies on the "data" key to be processed before the "try" key in the object, but the order of the items when you iterate them is undefined, and the order actually differs between browsers.
If you know that the items exists, you could just pick up the value from the object before the loop:
If you know that the items exists, you could just pick up the value from the object before the loop:
var test = $array.data;
ASKER
Open in new window
Actual fact is i would like to store this outer array into a variable and use it inside the loop.
for instance
Open in new window
Open in new window
However I keep getting undefined message.