Angular - call function after all JS is loaded


User 1857116

I want to call a function when all files (JS) are loaded (because I want to call a function inside one of the files). How do I do this?

     .state('dashboard', {
         url: "/dashboard.html",
         templateUrl: "views/dashboard.html",            
         data: {pageTitle: 'Dashboard'},
         controller: "DashboardController",
         resolve: {
             deps: ['$ocLazyLoad', function($ocLazyLoad) {
                 return $ocLazyLoad.load({
                     name: 'MetronicApp',
                     insertBefore: '#ng_load_plugins_before', 
                     files: [
                         '/assets/global/plugins/morris/morris.css',
                         '/assets/admin/pages/css/tasks.css',

                         '/assets/global/plugins/morris/morris.min.js',
                         '/assets/global/plugins/morris/raphael-min.js',
                         '/assets/global/plugins/jquery.sparkline.min.js',

                         '/assets/admin/pages/scripts/index3.js',
                         '/assets/admin/pages/scripts/tasks.js', 
                         //'/js_custom/dashboard.js', 

                         'js/controllers/DashboardController.js'
                     ] 
                 });
             }]
         }
     })

Source: Metronic Template AngularJS Version

Twill

Seems $ocLazyLoad.load()to have returned the promise. After all files are loaded, the problem should be resolved. The documentation has an example similar to what you want :

[...]
return $ocLazyLoad.load('js/ServiceTest.js').then(function() {
  var $serviceTest = $injector.get("$serviceTest");
  $serviceTest.doSomething();
});

Related


Angular - call function after all JS is loaded

User 1857116 I want to call a function when all files (JS) are loaded (because I want to call a function inside one of the files). How do I do this? .state('dashboard', { url: "/dashboard.html", templateUrl: "views/dashboard.html",

Angular - call function after all JS is loaded

User 1857116 I want to call a function when all files (JS) are loaded (because I want to call a function inside one of the files). How do I do this? .state('dashboard', { url: "/dashboard.html", templateUrl: "views/dashboard.html",

Angular - call function after all JS is loaded

User 1857116 I want to call a function when all files (JS) are loaded (because I want to call a function inside one of the files). How do I do this? .state('dashboard', { url: "/dashboard.html", templateUrl: "views/dashboard.html",

How to call a function after the page is fully loaded in Angular?

Akana I'm trying to call a function on a specific route after the page is fully loaded , like if the user logs in and goes to the main page route first, and successfully loads a function will call/call itself. constructor( private router: Router) { this.rout

Call the function after the page is loaded

Nitin I am using javascript in my html page. .I've been logging the time spent using the Navigation API. . When I try to find out the total load time (navigationStart-loadEventEnd), I find that loadEventEnd is 0. But also found that the loadEventStart value is

Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Call the function after the page is loaded

Nitin I am using javascript in my html page. .I've been logging the time spent using the Navigation API. . When I try to find out the total load time (navigationStart-loadEventEnd), I find that loadEventEnd is 0. But also found that the loadEventStart value is

Call function after AJAX is loaded

bull I have jQuery script that helps me to label rows in a table. I also have AJAX functionality to load other data into this table. My idea is that the Picker function is called every time after AJAX is used to tag that data. It works, but is very unstable -

Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Call function after instruction is loaded

Shashank I am working on custom directives for angular 1.6 I want to call a function after loading instructions. Is there a way to do this? I tried the link function but it seems that the link function is executed before the load instruction. Any help would be

Call function after AJAX is loaded

bull I have jQuery script that helps me to label rows in a table. I also have AJAX functionality to load other data into this table. My idea is that the Picker function is called every time after AJAX is used to tag that data. It works, but is very unstable -

Run a js function after all scripts on the page are fully loaded

PJW I'm trying to run a simple javascript function when the page is fully loaded. For example, this function: <script type="text/javascript"> function changeSize() { var el = document.getElementById("my-id"); el.style.height = "500px"; }; </script> My p

Run a js function after all scripts on the page are fully loaded

PJW I'm trying to run a simple javascript function when the page is fully loaded. For example, this function: <script type="text/javascript"> function changeSize() { var el = document.getElementById("my-id"); el.style.height = "500px"; }; </script> My p

Call js function after rendering Angular directive

Apu Bharat I'm trying to create a quick Angular directive that will generate a combobox using a jQuery UI extension I found. Extension is very simple. I just need to create a standard select element and run the function "combobox()" on it. I'm not sure where t

Call js function after rendering Angular directive

Apu Bharat I'm trying to create a quick Angular directive that will generate a combobox using a jQuery UI extension I found. Extension is very simple. I just need to create a standard select element and run the function "combobox()" on it. I'm not sure where t

Call mounted after all properties created are loaded

Anix In my Vue app, I fetch some data from a remote API and use that data to create a Html table. I decided to go with the following process. Get the data from created()the API in the hook and set the data property there, then in the mounted()hook call the met

How to call a function after the activity is loaded

kabeth wahra I have an activity using RecyclerView in Android. I tried to call getChildAt(i) on the RecyclerView in OnCreate but it returns null. I tried the same thing in a button click listener created for the test and it returns the item just fine. This mus

jQuery - call function after image is loaded

Simon So I have two functions. One to load the image and the other to resize its container element. Naturally, the image element needs to be loaded before any measurements can be made. It looks like this: var imgEl; loadImage(imgSrc); // only call the below,

call javascript function after script is loaded

Neeraj: I have a html page where i add html dynamically by javascript like below <script type="text/javascript" src="/myapp/htmlCode"></script> I want to call a js function, for example, loadedContent(); once the above script adds dynamic html. Can someone he

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Call function angularjs after directive is loaded

Deepak Bandi I have an isolated directive and my controller looks like: app.controller('ZacksController', ['$scope', '$http', 'ngDialog', '$timeout', function($scope, $http, ngDialog, $timeout){ //some code here }]); The HTML in the file looks like this:

Call a function before or after the API is fully loaded

cannon moyer I have a button and if it is clicked, I need to call a function that hides another element initialized by a js file that is loaded asynchronously. However, the only way to hide an element is through the Javacsript API. There is no ID or class assi

Call function angularjs after directive is loaded

Deepak Bandi I have an isolated directive and my controller looks like: app.controller('ZacksController', ['$scope', '$http', 'ngDialog', '$timeout', function($scope, $http, ngDialog, $timeout){ //some code here }]); The HTML in the file looks like this:

Call Javascript function after AJAX is loaded

Laurin Starr I know these questions pop up here. I'm usually not the type to ask questions, but this time I couldn't find a solution by searching. I boiled the problem down to a very simple environment: I have 3 files: Index.php: <html> <html xmlns="http://www

Call function after page is loaded in new tab

Walter After the button is clicked, I need to open some links in a new tab, and more than once the page loads, so I need to programmatically perform some action on this page (e.g. click the appropriate GUI element, etc.). For example, this code should open in

Call function after page is loaded in new tab

Walter After the button is clicked, I need to open some links in a new tab, and after the page is loaded, I need to programmatically perform some actions on this page (eg click on the appropriate GUI element, etc.). For example, this code should open in a new

How to call a function after the activity is loaded

kabeth wahra I have an activity using RecyclerView in Android. I tried to call getChildAt(i) on the RecyclerView in OnCreate but it returns null. I tried the same thing in a button click listener created for the test and it returns the item just fine. This mus

call javascript function after script is loaded

Neeraj: I have a html page where i add html dynamically by javascript like below <script type="text/javascript" src="/myapp/htmlCode"></script> I want to call a js function, for example, loadedContent(); once the above script adds dynamic html. Can someone he