javascript - 基于条件的 Angular 模块

标签 javascript angularjs angularjs-module

有没有办法根据 Controller 内部的条件加载/指定模块?

var app = angular.module('app',['ngRoute']);

app.controller("DemoCtrl",["$scope",function($scope){
   var a = true;
   if(a)
     // Load "Yes" module to app
   else
     // Load "No" module to app
}]);

最佳答案

在 Angular 中没有开箱即用的直接方法来执行此操作,但是您可以考虑使用 ocLazyLoad module .

链接页面上给出的示例显示了如何将其用于您的案例:

myApp.controller("MyCtrl", function($ocLazyLoad) {
    $ocLazyLoad.load('testModule.js');
});

关于javascript - 基于条件的 Angular 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32785589/

相关文章:

javascript - Angular Directive(指令)

angularjs - 配置 AngularJS 模块 - 它如何影响应用程序中的其他模块?

AngularJS:使用多模块并在模块之间进行通信?

javascript - 使用 Vue 和 AXIOS 从 API 循环构建数组

javascript - 在鼠标输入上打开 div 并保持打开状态

javascript - ExtJS DirectStore 中字段的元数据配置

javascript - 如何使用 angular-strap 模态的 onHide 选项

angularjs - 为什么 node_modules 文件夹没有提交给 Git?

javascript - AngularJS错误: $injector:unpr Unknown Provider githubProvider <- github <- MainController

javascript - 为什么这个 JavaScript 不工作?