Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在控制台中报告角度相关性的导入模块错误_Javascript_Angularjs_Angularjs Directive_Dependencies - Fatal编程技术网

Javascript 如何在控制台中报告角度相关性的导入模块错误

Javascript 如何在控制台中报告角度相关性的导入模块错误,javascript,angularjs,angularjs-directive,dependencies,Javascript,Angularjs,Angularjs Directive,Dependencies,我在写一组有角度的指令。其中一些将使用其他角度相关性(例如,ngFileUpload,ui-select)。目前,我声明所有这些内容如下: angular.module('module1', ['ngFileUpload']) .directive('MyDirective1NeedNgFileUpload', function() { // ... }); angular.module('module2', ['ui-select']) .directive('My

我在写一组有角度的指令。其中一些将使用其他角度相关性(例如,
ngFileUpload
ui-select
)。目前,我声明所有这些内容如下:

angular.module('module1', ['ngFileUpload']) 
  .directive('MyDirective1NeedNgFileUpload', function() {
     // ...
  });

angular.module('module2', ['ui-select']) 
  .directive('MyDirective1NeedUiSelect', function() {
     // ...
  });

angular.module('myLibrary', ['module1', 'module2']);
<html>
<body>
  ...
  <script src="/path/to/ng-file-upload.js"></script>
  <script src="/path/to/ui-select.js"></script>
  <script src="/path/to/myLibrary.js"></script>
  <script src="app.js"></script>
</body>
</html>

// in app.js
angular.module('myapp', [
  'myLibrary', 
  'ngFileUpload',
  'ui-select'
]);
通常,用户必须在实际应用程序中包含三个js文件,如下所示:

angular.module('module1', ['ngFileUpload']) 
  .directive('MyDirective1NeedNgFileUpload', function() {
     // ...
  });

angular.module('module2', ['ui-select']) 
  .directive('MyDirective1NeedUiSelect', function() {
     // ...
  });

angular.module('myLibrary', ['module1', 'module2']);
<html>
<body>
  ...
  <script src="/path/to/ng-file-upload.js"></script>
  <script src="/path/to/ui-select.js"></script>
  <script src="/path/to/myLibrary.js"></script>
  <script src="app.js"></script>
</body>
</html>

// in app.js
angular.module('myapp', [
  'myLibrary', 
  'ngFileUpload',
  'ui-select'
]);

...
//在app.js中
角度.module('myapp'[
“我的图书馆”,
“ngFileUpload”,
“用户界面选择”
]);
如果我只在应用程序1中使用
module1
,我根本不需要
ui选择。但我仍然需要包括
ui选择
,否则浏览器将报告一个错误
Uncaught错误:[$injector:modulerr]http://errors.angularjs.org/...

我想问/做的是,我想延迟加载第三个依赖项,只有在真正需要它们的时候,或者只是简单地抛出一个关于缺少什么的更具体的错误消息


这怎么可能呢?

正如您所说,一些用户可能只需要
module1
功能,有些则需要
module2
功能

您还可以将库发布为一个组合模块
angular.module('myLibrary',['module1','module2')

由于
module1
module2
单独使用,请在文档中告知用户可以单独使用该模块或
myLibrary
使用组合功能

angular.module('userApp', ['module1']);// in case single module is enough for user
angular.module('userApp', ['myLibrary']); // incase both module features will be used

在我的实际案例中,我有一个指令
,它可以是一个输入,或者是一个下拉列表,或者是一个日期时间选择器,或者是一个文件上传。如果用户从不使用文件上传,则不必包含
ng file upload.js
。若用户从不使用下拉列表,那个么他们就不必包括
ui-select.js
。假设有些库相当大,我会找到一种按需加载库的方法。谢谢你的回复。我最初的描述可能是错误的。我已在原来的问题中说明了更多细节。