I need to access a scope variable within javascript code. I tried various
approaches including a few I found on this forum and internet but didn't
get any to work. The last code I have looks like this:
<body ng-app="testApp">
<div id="div1" ng-controller="testCtrl">
{{testString}}
<script>
var scope = angular.element($("#div1")).scope();
alert(scope.testString);
</script>
</div>
</body>
I can see testString being rendered in the html,
angular.element($("#div1")) is defined but scope() returned an undefined,
hence the alert doesn't work. How can I get this to work?
I also created a plnkr.
http://plnkr.co/edit/WOsQ7qfvHOPJRHoUIJCR?p=preview
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.