簡體   English   中英

如何在控制台中報告導入模塊錯誤以獲取Angular依賴性

[英]How to report import module error in console for Angular dependency

我正在編寫一組Angular指令。 其中一些將使用其他3rd Angular依賴項(例如ngFileUploadui-select )。 目前,我將所有這些聲明如下:

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

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

angular.module('myLibrary', ['module1', 'module2']);

通常,用戶必須在真實的​​應用程序中包括三個js文件,如下所示:

<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'
]);

如果僅在應用程序1中使用module1 ,則根本不需要ui-select 但是我仍然需要包括ui-select ,否則瀏覽器將報告錯誤Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/...

我想問/做的是,我想僅在確實需要它們時才懶加載第三種依賴關系,或者只是拋出關於缺少的依賴項的更具體的錯誤消息。

這怎么可能?

因此,正如您所說,某些用戶可能只需要module1功能,而某些module2則需要兩者。

您將庫發布為組合模塊,也發布為angular.module('myLibrary', ['module1', 'module2']);

隨着module1module2本身的發展,請在您的文檔中告知用戶可以單獨使用該模塊,也可以將myLibrary用於組合功能。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM