$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'); }] } })
这个一个很官方的例子:有时间多上官网看看api 这里的。
注意他返回的是一个promise对象
还有另一种用法:
function ($ocLazyLoad) { return $ocLazyLoad.load(['ngGrid', 'toaster']).then( function () { return $ocLazyLoad.load('javascripts/controllers/template/tmplist.js'); } ); }]
这里我们还可以看很多的东西:http://www.mamicode.com/info-detail-407754.html
这个是这个服务的官网:
https://oclazyload.readme.io/docs/oclazyload-service