Consider basic AngularJS application with just one controller. Inside the controller I have set-up "myVariable" to hold a value "Test".
I am given an inline JavaScript code in the view and I need to call a function samplefunction which takes a parameter using myVariable.
/* Controllers */
angular.module('myApp.controllers', [])
.controller('MainCtrl', ['$scope', function($scope) {
$scope.myVariable = "Test";
});
In the view, in the html file, this is what I need to do:
<script type="text/javascript">
var param1 = {{myVariable}}; /* <-- how to make this work? */
samplefunction( param1 );
</script>
It doesn't work though. I just need to assign myVariable value to the param1. I also tried something like:
...
var param1 = angular.element(document.getElementById("mainBody")).scope().myVariable
...
But this didn't work either. Please, note that I cannot touch the given JS code that I am calling in the view.
Anyone knows how to solve this simple issue?
angular.element(document.getElementById("mainBody")).scope().myVariableshould work - what is the output