2
schangxiang@126.com
2024-08-16 b47c50a2a514def7374b32d7194b2c599cba5625
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
angular.module('app').controller('AppCtrl', function($scope, $ocLazyLoad) {
  $scope.$on('ocLazyLoad.moduleLoaded', function(e, params) {
    //console.log('event module loaded', params);
  });
 
  $scope.$on('ocLazyLoad.componentLoaded', function(e, params) {
    //console.log('event component loaded', params);
  });
 
  $scope.$on('ocLazyLoad.fileLoaded', function(e, file) {
    console.log('event file loaded', file);
  });
 
  $scope.loadBootstrap = function() {
    // use events to know when the files are loaded
    var unbind = $scope.$on('ocLazyLoad.fileLoaded', function(e, file) {
      if(file === 'bower_components/bootstrap/dist/css/bootstrap.css') {
        $scope.bootstrapLoaded = true;
        unbind();
      }
    });
    // we could use .then here instead of events
    $ocLazyLoad.load([
      'bower_components/bootstrap/dist/js/bootstrap.js',
      'bower_components/bootstrap/dist/css/bootstrap.css'
    ]);
  };
});