1

I want a loader to be running when an external JS is loaded in an angular project How can it be implemented? I have loaded the JS with the help of webPack.

JS is loaded on the click and it takes some time to get loaded. I want that the loader should be running until JS is not loaded completely to the DOM. I want to implement the loader at the common place.

{
        path: 'pharmacy',
        loadChildren: () => {
            return loadScript('/deploy/pharmacy.js?timestamp=' + getDateTime(), 'dhsapp', 'AppModule');
        },
        data: { breadcrumb: 'Pharmacy', type: 'App' },

    },
liqSTAR
  • 1,225
  • 1
  • 12
  • 22
  • Could you elaborate what you really want? So you want to load a `loader` after an external js has been loaded? Quite confusing. – liqSTAR Jun 07 '19 at 08:29
  • As i click to open external js from my project it takes some time to load i want that a loader should run until js is completely loaded............. i want that – NAMAN GUPTA Jun 07 '19 at 09:00
  • You tried using `Promises`? https://developer.mozilla.org/de/docs/Web/JavaScript/Reference/Global_Objects/Promise I would load the script inside the component inside the constructor. Check this out as well: https://stackoverflow.com/questions/34489916/how-to-load-external-scripts-dynamically-in-angular/34489991 – liqSTAR Jun 07 '19 at 09:20
  • actually js which we are loading is an seprate project which we want to load at a particlar point thus it cant be taken inside a constructer – NAMAN GUPTA Jun 11 '19 at 12:49

1 Answers1

0

Use loader template in your html file set variable true while data is loading from network after data comes make it false,Render loader template on basis of variable value is true or false, Also you can create separate component or custom directive for loader and render it at many places in your application by declaring variable true or false

bhalesh
  • 22
  • 2