0

Here's the fiddle http://jsfiddle.net/altermind/yak10smq/1/

I need to declare variable 'appetite' in the controller 'EntrynewCtrl', then pass it to the javascript function, something like that:

  <script>
    var a = appetite;
    </script>

When I do "console.dir(scope);" I see in console:

$$childScopeClass

I can allocate that variable via console, but have no idea how to access it in the script.

UPD: gave wrong fiddle, now it's correct

6
  • Why do you want to do this? what do you want to accomplish in doing this? Commented Aug 22, 2014 at 5:08
  • I'm building the web app with Angularjs. For certain tasks I need JSXGraph library. Get variables from mongodb with controller and pass those to the script. I guess the proper way will be to build separate directive for JSXGraph library, but right now I need very quick solution for the prototype. Commented Aug 22, 2014 at 5:12
  • @altermind What's the problem though? In your fiddle it looks like you're able to grab the scope. If there's a property on it called appetite and you want to access it, wouldn't it just be var a = scope.appetite;? Commented Aug 22, 2014 at 5:28
  • @AnthonyChu I can view $$childScopeClass (in console with console.dir(scope)), and I can clearly see 'appetite' variable there, but cannot access it for some reason. Commented Aug 22, 2014 at 5:35
  • Seems to work? jsfiddle.net/rxtqm994 Commented Aug 22, 2014 at 5:43

2 Answers 2

1

Please try this,

angular.element('#YOUR-ELEMENT-SELECTOR').scope().$apply(function(scope){
  scope.doStuff();
});

Another way,

angular.element('.ng-scope').each(function(e, t){  
    console.log(t,angular.element(t).scope());
});
Sign up to request clarification or add additional context in comments.

Comments

0

you may need this tool AngularJS Batarang read this blog for more detail Debugging AngularJS Apps from the Console

 angular.element(targetNode).scope()

-> ChildScope {$id: "005", this: ChildScope, $$listeners: Object, $$listenerCount: Object, $parent: Scope…}

angular.element(targetNode).isolateScope()

-> Scope {$id: "009", $$childTail: ChildScope, $$childHead: ChildScope, $$prevSibling: ChildScope, $$nextSibling: Scope…}

Comments

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.