When working with the code snippet below in angularJS,
<script type="text/javascript">
angular.module('app').controller('add', ['$scope',function($scope) {
$scope.name = "Bonita Ln";
}]);
</script>
The corresponding Javascript code to access $scope
variable member name
is as follows:
<div ng-app="app" ng-controller="add">
<script type="text/javascript">
var dom_el = document.querySelector('[ng-controller="add"]');
var ng_el = angular.element(dom_el);
var ng_el_scope = ng_el.scope();
var name = ng_el_scope.name;
</script>
</div>
Here is an example of angular code that accesses the ng-init
variable name
using angular expression:
<body ng-app="">
<div ng-init="name='Bonita Ln'">
{{name}}
</div>
</body>
Now, the question arises, how can one access the ng-init
variable name
using JavaScript?