有没有办法根据 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/