正在开发Angularjs项目,其中需要根据需要加载css和js文件。为此,我在angularjs中使用了oc.lazyLoad库,但有时页面加载了罚款,有时候会产生错误加载的文件。以下是我的代码:
.state('datetimepickers', {
url: "/date-time-picker",
templateUrl: "views/date-time-picker.php",
data: {pageTitle: 'Date-Time Pickers'},
controller: "DateTimePickerController",
resolve: {
deps: ['$ocLazyLoad', function($ocLazyLoad) {
return $ocLazyLoad.load({
name: 'datetimepicker',
insertBefore: '#ng_load_plugins_before', // load the above css files before a LINK element with this ID. Dynamic CSS files must be loaded between core and theme css files
files: [
'assets/global/plugin/bootstrap-datepicker/css/datepicker.css',
'assets/global/plugin/bootstrap-datepicker/css/bootstrap-datetimepicker.min.css',
'assets/global/plugin/bootstrap-datepicker/css/bootstrap-timepicker.min.css',
'assets/global/plugin/bootstrap-datepicker/css/daterangepicker.css',
'assets/global/plugin/bootstrap-datepicker/css/clockface.css',
'assets/global/plugin/bootstrap-datepicker/js/bootstrap-datepicker.js',
'assets/global/plugin/bootstrap-datepicker/js/bootstrap-timepicker.js',
'assets/global/plugin/bootstrap-datepicker/js/clockface.js',
'assets/global/plugin/bootstrap-datepicker/js/bootstrap-datetimepicker.min.js',
'assets/global/plugin/bootstrap-datepicker/js/moment.js',
'assets/global/plugin/bootstrap-datepicker/js/daterangepicker.js',
'js/controllers/DateTimePickerController.js'
]
});
}]
}
})
有时它的工作正常,但是当页面重新加载时会产生如下错误:
错误:时刻不是一个功能 DateRangePicker @ http://localhost/angular/angular/assets/global/plugin/bootstrap-datepicker/js/daterangepicker.js:34:26 $ .fn.daterangepicker /< @ http://localhost/angular/angular/assets/global/plugin/bootstrap-datepicker/js/daterangepicker.js:1615:40 。每个@ http://localhost/angular/angular/assets/global/js/jquery-2.2.4.min.js:2:2859 n.prototype.each@http://localhost/angular/angular/assets/global/js/jquery-2.2.4.min.js:2:843 $.fn.daterangepicker@http://localhost/angular/angular/assets/global/plugin/bootstrap-datepicker/js/daterangepicker.js:1611:9 @ http://localhost/angular/angular/js/controllers/DateTimePickerController.js:132:5 。VF /这$ gethttp://localhost/angular/angular/assets/global/plugin/angularjs/angular.min.js:147:42 沃顿http://localhost/angular/angular/assets/global/plugin/angularjs/plugins/angular-ui-router.min.js:7:23267 Y / k.compile / HTTP://localhost/angular/angular/assets/global/plugin/angularjs/plugins/angular-ui-router.min.js:7:23401 。VF /这$ gethttp://localhost/angular/angular/assets/global/plugin/angularjs/angular.min.js:147:483 V / y.transitionTo / y.transition< @ http://localhost/angular/angular/assets/global/plugin/angularjs/plugins/angular-ui-router.min.js:7:18767 E /< @ http://localhost/angular/angular/assets/global/plugin/angularjs/angular.min.js:130:409 。VF /这$ gethttp://localhost/angular/angular/assets/global/plugin/angularjs/angular.min.js:145:103 。VF /这$ gethttp://localhost/angular/angular/assets/global/plugin/angularjs/angular.min.js:142:165 。VF /这$ gethttp://localhost/angular/angular/assets/global/plugin/angularjs/angular.min.js:145:399 升@ http://localhost/angular/angular/assets/global/plugin/angularjs/angular.min.js:97:248 沃顿http://localhost/angular/angular/assets/global/plugin/angularjs/angular.min.js:101:373 GG / HTTP://localhost/angular/angular/assets/global/plugin/angularjs/angular.min.js:102:397