I have Angularjs variable that I want to pass in javascript variable. I found solution here so it didn't work. My code :
<script>
var demo=angular.module('demo', []);
demo.controller('metrics', function($scope, $http) {
$http.get('http://localhost:8080/metrics').then(function(response)
{
$scope.metrics = response.data;
});
});
</script>
<div ng-controller="metrics">
<p>{{metrics}}<p>
</div>
<script>
var e = angular.element(document.querySelector('[ng-controller="metrics"]'));
var e1 = e.scope().metrics ;
alert(e1)
</script>
I got result from {{metrics}} but e1 didn't return something.
Thanks for your help.
$scope.metrics
will be populated quite a bit later than you're trying to get it. It's a bad idea to poke around the innards of Angular like this anyway; you should angularify that bit of Javascript there; what exactly are you trying to do?