AngularJS,不能添加模块

AngularJS, cannot add modules

本文关键字:模块 添加 不能 AngularJS      更新时间:2023-09-26

所以我对AngularJS很陌生,我似乎无法添加额外的模块,例如d3用于图形。

所以我添加新模块的代码是

  (function() {
  'use strict';
  angular
    .module('infographicsModule', ['ngAnimate', 'ngCookies', 'ngTouch', 'ngSanitize', 'ngMessages', 'ngAria', 'ngResource', 'ui.router', 'ui.bootstrap', 'toastr']);
})();

但是如果我尝试将d3添加为附加模块,则会引发错误

Uncaught Error: [$injector:modulerr] Failed to instantiate module infographicsModule due to:
Error: [$injector:modulerr] Failed to instantiate module d3 due to:
Error: [$injector:nomod] Module 'd3' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

有什么建议吗?如果你需要更多的代码,我可以发布它。

也许发生这种情况是因为 D3 不是一个角度模块。

您可以尝试使用以下链接执行此操作:https://github.com/WealthBar/angular-d3

或者,您可以封装在服务或工厂中并从中调用。