0

I have JS file with simple function on clear JS:

function Alert(){
  alert();
}

In another file I have application on Angular JS. At first connected simple JS file on page and after Angular JS on tags <head>

How I can call Alert() method from 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 get error:

Uncaught ReferenceError: leftTimeInit is not defined

1 Answer 1

1

You shouldn't do DOM manipulations in your controllers. So you should probably rethink how you want to use that function.

Anyway, leftTimeInit is declared in an anonymous function, and only visible there. You can't call it anywhere else. If you want that, you'll have to move it out of $(function(){}) . But as I've said, not recommended.

As for your Alert() example... In Angular you have access to simple JS global functions via $window (of course, they're global and you could access them anyway, but if you use $window you can mock them in tests).

.controller('Ctrl', function ($scope, $window) {
  $window.Alert('something');
});
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.