1

例子:

angular.module("app", ['someServices'])

如果someServices不存在,将收到错误消息:

Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:modulerr] Failed to instantiate module pascalprecht.translate32 due to:
Error: [$injector:nomod] Module 'someServices' 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.

但是现在,我想让它继续运行,这意味着如果它加载失败然后忽略它。

是否有一些配置?

4

1 回答 1

1

我仍然不明白你为什么需要这样做。但是仅依靠 AngularJS 是无法解决的。如果你想做这样的事情,你总是可以先检查模块的存在,如果不存在就不要将它包含在依赖项中。像这样的东西:

var dependencies = [];
if (angular.module('someServices')) dependencies.push( 'someServices' );
var myApp = angular.module("app", dependencies);
于 2014-03-07T21:37:17.440 回答