I need to call an angularJS function from a javascript function. This is my javascript function:
function callAngularFunction(userid, serviceid, system) {
angular.element(document.getElementById('myServiceId')).scope().test();
}
This is my controller code:
serviceApp.controller('myService', function ($scope, $location, $window) {
$scope.test = function () {
console.log("hello from test");
}
});
And this is how I included it in html:
<body ng-app="serviceApp" ng-controller="myService" id="myServiceId">
Whenever I call callAngularFunction, I get this error:
TypeError: Cannot read property 'test' of undefined
myServiceIdin theDOM. To check it just executedocument.getElementById('myServiceId')in your debugger console. It should print undefined if the element is not found.callAngularFunctionfrom my localhost project. But i'm new and have no idea how to proceed from hereCSS selector(w3schools.com/cssref/css_selectors.asp) (id, unique class or property) and then try to select it withdocumnet.querySelector()(instead ofdocument.getElementById())