How to call JS function outside from AngularJS app? -
i have js file simple function on clear js:
function alert(){ alert(); }
in file have application on angular js. @ first connected simple js file on page , after angular js on tags <head>
how can call alert()
method controller angular js?
simple js file:
$(function(){ function lefttimeinit(){ $.each($('.action-loader'), function(index, val) { initloader($(this), $(this).data('percentage')); }); } });
angular js in controller:
lefttimeinit();
i error:
uncaught referenceerror: lefttimeinit not defined
you shouldn't dom manipulations in controllers. should rethink how want use function.
anyway, lefttimeinit
declared in anonymous function, , visible there. can't call anywhere else. if want that, you'll have move out of $(function(){})
. i've said, not recommended.
as alert() example... in angular have access simple js global functions via $window (of course, they're global , access them anyway, if use $window can mock them in tests).
.controller('ctrl', function ($scope, $window) { $window.alert('something'); });
Comments
Post a Comment