尝试使用 oclazyload 将 Angular 模块注入我的主模块。请注意,我目前没有使用 RequireJs 或 oclazyload 来加载 JavaScript 文件。现在我在 Index HTML Script 标签中添加了模块。
注入方法执行没有任何错误。但是当我记录 $ocLazyLoad.getModules() 时,我没有看到我想要注入的模块。
非常感谢任何帮助。
内联脚本:
<script type="text/javascript">
var app = angular.module("ngNextGenWidget", []); //This is the module to be injected
app.factory('nextGenWidget', function () {
return {
constructControl: function ($compile, $scope) {
//Compile html fragment
var compileFunction = $compile("<div tools-Home-Page></div>")
//Get html output from directive after applying $scope
var htmloutputFromDirective = compileFunction($scope);
return htmloutputFromDirective;
}
}
});
app.directive('toolsHomePage', function () {
return {
restrict: 'A',
scope: true,
templateUrl: '/Content/Templates/DemoTemplate-1.html',
controller: ['$scope', function ($scope) {
$scope.name = 'Home Page';
}]
}
});
</script>
主应用:
appLazy.directive('testComponent', function () {
return {
restrict: 'E',
link: function (scope, element, attrs) {
scope.Execute(attrs, element, attrs.moduleName);
},
controller: ['$scope', '$compile', '$ocLazyLoad',
function ($scope, $compile, $ocLazyLoad) {
$scope.Execute = function (attr, element, moduleName) {
$ocLazyLoad.inject(moduleName);//trying to inject the module
var htmloutputFromDirective =
$nextGenWidget.constructControl($compile, $scope);
$(element).append(htmloutputFromDirective);
}
}]
};
});