有条件地加载 ng-animate 模块?
Conditionally load ng-animate module?
我们正在使用 Angular 1.4.9 ng-animate 模块。一切正常,但我们的一些团队要求一种不根据条件加载的方法。
例如,在特定平台或用户代理上,没有 ng-animate 加载。
我们已经有一些方法来对此进行测试 (e.g.modernizr) 并使用这些方法有条件地加载其他 .js 和 .css 文件,但是由于 ng-animate 是一个简单地排除的模块它的 js 文件会抛出错误。
如果您 bootstrap 手动申请,实际上非常简单。
将您的依赖项保存在全局变量中:
window.myApplicationMeta = {
dependencies: [j]
};
定义模块时使用它:
angular.module('myApp', applicationMeta.dependencies)
在 bootstrap 应用程序之前修改依赖项:
angular.element(document).ready(function() {
var condition = true;
if (condition) applicationMeta.dependencies.push('ngAnimate');
angular.bootstrap(document, ['myApp']);
});
我们正在使用 Angular 1.4.9 ng-animate 模块。一切正常,但我们的一些团队要求一种不根据条件加载的方法。
例如,在特定平台或用户代理上,没有 ng-animate 加载。
我们已经有一些方法来对此进行测试 (e.g.modernizr) 并使用这些方法有条件地加载其他 .js 和 .css 文件,但是由于 ng-animate 是一个简单地排除的模块它的 js 文件会抛出错误。
如果您 bootstrap 手动申请,实际上非常简单。
将您的依赖项保存在全局变量中:
window.myApplicationMeta = {
dependencies: [j]
};
定义模块时使用它:
angular.module('myApp', applicationMeta.dependencies)
在 bootstrap 应用程序之前修改依赖项:
angular.element(document).ready(function() {
var condition = true;
if (condition) applicationMeta.dependencies.push('ngAnimate');
angular.bootstrap(document, ['myApp']);
});