As per my point of view this error can be because of the following two points:
1. If the ID is not provided to the element correctly.
2. If the function is called before the DOM is loaded therefore try to write your function call inside the window.onload event.
Example:
<body ng-app="app">
<div id="mainDiv" ng-controller="MyCtrl">
<input type="button"/ id="temp">
</div>
</body>
angular.module('app', [])
.controller('MyCtrl', function ($scope) {
$scope.anyFunc = function () {
alert("I am called from jQuery");
};
});
window.onload = function () {
$("#temp").on("click",function()
{
angular.element($("#mainDiv")).scope().anyFunc();
});
}
Hope it helps...!
0 Comment(s)