Because of stupid third-party reasons, I need to access $scope from the html.
This is what I'm attempting:
<html ng-app>
<!-- head goes here-->
<body>
<!--Body goes here-->
<script type="text/javascript">
console.log($scope);
</script>
</body>
</html>
To examine the scope in the debugger: Right click on the element of interest in your browser and select 'inspect element'. You should see the browser debugger with the element you clicked on highlighted. The debugger allows you to access the currently selected element in the console as $0 variable.
You could use the following in the console: angular. element(document. querySelector('[ng-controller=hw]')).
39) Do you think that parent controller can access the methods of child controller or vice versa? No, the parent controller cannot access the methods of child controller, but the child controller can access the methods of the parent controller.
The ng-controller directive adds a controller to your application. In the controller you can write code, and make functions and variables, which will be parts of an object, available inside the current HTML element.
Because angular
is exposed globally, you can use:
var scope = angular.element().scope()
For example if you have this in your markup
<div ng-controller="someCtrl" id="someId">{{test}}</div>
You can access the isolated scope of the controller someCtrl
like this:
var scope = angular.element($("#someId")).scope()
scope.test = "Hello, world!";
(you might want to $apply the scope as well, see here)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With