ocombe / ocLazyLoad

Lazy load modules & components in AngularJS
https://oclazyload.readme.io
MIT License
2.63k stars 510 forks source link

Two js files in a module, one js file should be loaded before the other one #339

Closed youyouttok closed 8 years ago

youyouttok commented 8 years ago

Hello, angular-chart depend on Chart.js , but Chart.js could not be loaded before angular-chart.js.

app.constant("Modules_Config", [{
    name: "ui.chart",
    module: true,
    files: [
      "../js/swan/chart/Chart.js", "../js/swan/chart/angular-chart.js"
    ]
  }])
  .config(["$ocLazyLoadProvider", "Modules_Config", routeFn]);

function routeFn($ocLazyLoadProvider, Modules_Config) {
  $ocLazyLoadProvider.config({
    debug: false,
    events: false,
    modules: Modules_Config
  });
};
.state("mainPage", {
    url: "/mainPage",
    views: {
      "": {
        templateUrl: "mainPage.html"
      }
    },
    resolve: {
      deps: ["$ocLazyLoad", function($ocLazyLoad) {
        return $ocLazyLoad.load([
          'ui.chart',
          '../js/controller/chartController.js'
        ]);
      }]
    }
  })

image

insidewhy commented 8 years ago

@youyouttok You could search for the first module's existence in an $interval and then load the next one. That's how I've done it. Can give you the code if you need it.

ocombe commented 8 years ago

or you could use the parameter serie: true so that it loads your files in serie

insidewhy commented 8 years ago

Shouldn't that be series?

ocombe commented 8 years ago

From the docs:

$ocLazyLoad.load({
  serie: true,
  files: [
    'bower_components/angular-strap/dist/angular-strap.js',
    'bower_components/angular-strap/dist/angular-strap.tpl.js'
  ]
});
insidewhy commented 8 years ago

There is no word serie in the English language, I believe you intended to use series.

insidewhy commented 8 years ago

Although serial would probably be a more appropriate term here.

ocombe commented 8 years ago

Sure.

Le jeu. 1 sept. 2016 20:46, Mr Friend notifications@github.com a écrit :

There is no word serie in the English language, I believe you intended to use series.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/ocombe/ocLazyLoad/issues/339#issuecomment-244136222, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQMom1071ylMynS5oj6a23_dps6G36Rks5qlv5jgaJpZM4JswIs .

youyouttok commented 8 years ago

@ocombe Thank you!I used serie in module config, and in route like this:

resolve: {
            loadModule: ["$ocLazyLoad", function($ocLazyLoad) {
                console.log(1);
                return $ocLazyLoad.load(['ui.chart']);
            }],
            loadMyCtrl: ['$ocLazyLoad', 'loadModule', function($ocLazyLoad, loadModule) {
                console.log(2);
                return $ocLazyLoad.load({
                    files: ['../js/controller/chartController.js']
                });
            }]
        }

it works!

youyouttok commented 8 years ago

@ohjames Thank you! I have used serie to solve the problem. I will try to use your solution to do it.

insidewhy commented 8 years ago

My solution was not good, it's much better to use serie, you can compose the promise it returns for more advanced dependency trees.