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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
'use strict';
 
// Declare app level module which depends on filters, and services
var App = angular.module('app', ['ui.router', 'oc.lazyLoad'])
  .config(function($stateProvider, $locationProvider, $urlRouterProvider, $ocLazyLoadProvider) {
    $urlRouterProvider.otherwise("/");
    $locationProvider.hashPrefix('!');
 
    // You can also load via resolve
    $stateProvider
      .state('index', {
        url: "/", // root route
        views: {
          "lazyLoadView": {
            controller: 'AppCtrl', // This view will use AppCtrl loaded below in the resolve
            templateUrl: 'partials/main.html'
          }
        },
        resolve: { // Any property in resolve should return a promise and is executed before the view is loaded
          loadMyCtrl: ['$ocLazyLoad', function($ocLazyLoad) {
            // you can lazy load files for an existing module
            return $ocLazyLoad.load('js/AppCtrl.js');
          }]
        }
      })
      .state('modal', {
        parent: 'index',
        resolve: { // Any property in resolve should return a promise and is executed before the view is loaded
          loadOcModal: ['$ocLazyLoad', '$injector', '$rootScope', function($ocLazyLoad, $injector, $rootScope) {
            // Load 'oc.modal' defined in the config of the provider $ocLazyLoadProvider
              console.log('load');
            return $ocLazyLoad.load([
                'bower_components/bootstrap/dist/css/bootstrap.css', // will use the cached version if you already loaded bootstrap with the button
                'bower_components/ocModal/dist/css/ocModal.animations.css',
                'bower_components/ocModal/dist/css/ocModal.light.css',
                'bower_components/ocModal/dist/ocModal.js',
                'partials/modal.html'
              ]).then(function() {
                console.log('--------then');
              $rootScope.bootstrapLoaded = true;
              // inject the lazy loaded service
              var $ocModal = $injector.get("$ocModal");
                console.log($ocModal);
              $ocModal.open({
                url: 'modal',
                cls: 'fade-in'
              });
            });
          }],
 
          // resolve the sibling state and use the service lazy loaded
          setModalBtn: ['loadOcModal', '$rootScope', '$ocModal', function(loadOcModal, $rootScope, $ocModal) {
            $rootScope.openModal = function() {
              $ocModal.open({
                url: 'modal',
                cls: 'flip-vertical'
              });
            }
          }]
        }
      });
 
    // Without server side support html5 must be disabled.
    $locationProvider.html5Mode(false);
 
    // We configure ocLazyLoad to use the lib script.js as the async loader
    $ocLazyLoadProvider.config({
      //debug: true,
      //events: true,
      modules: [{
        name: 'gridModule',
        files: [
          'js/gridModule.js'
        ]
      }]
    });
  });