0

Do you know how to use dynamic/chained variables inside a controller variable definition?

I have created this plnkr to further outline what I am trying to achieve: http://plnkr.co/edit/xOjhf8b7ZIxVhc1Id3xo

In the NodeCtrl, I am trying to dynamically access a node from a json object and I can't find the correct syntax to write out the chain.

I have tried a number of combinations but haven't found the correct way yet:

  //var jsonChunk = "data." + $scope.transcendType;
    $scope.tabinventory =  data.$scope.transcendType; 
                         //data;
                         //jsonChunk; 
                         //function() { return "data." + $scope.transcendType; };
    alert($tabinventory[0].title)
  //alert($scope.tabinventory.project[0].title);

Any help you could provide would be greatly appreciated.

All the best,

Ben

2
  • data within success handler is the object represented by your JSON. It has no property $scope nor any property transcendType so very hard to figure out what you are trying to get. Also demo throws errors from undefined function scope.getNodeByID Commented Oct 28, 2013 at 16:10
  • Using [ ] as my "index" was what was throwing me: plnkr.co/edit/2oHBuJUi1FWmiugy0nrr?p=preview Commented Oct 28, 2013 at 17:23

1 Answer 1

0

Have you tried logging $scope.transcendType to make sure it's properly defined in that context?

Assuming it's properly defined, try data[$scope.transcendType].

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

5 Comments

stop posting personal contact info. This site is intended for help to occur here so others in future can use responses as help also
I always post results back to Stack. I like to help people live & they like it too, then everyone gets to see the result. Win-win-win!
that;s irrelevant... not proper to post contact info here, or solicit direct contact...use profile for that and use chat system if need to
So you're advocating a worse user experience just to strictly follow the rules? Consider a career in law enforcement ;)
no...you are obviously new here... nobody posts contact info....it's tacky. Just advocating playing nice in the sandbox

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.