尝试使用oclazyload将Angular模块注入主模块。请注意,我目前没有使用RequireJs或oclazyload来加载JavaScript文件。 现在我在Index HTML Script标签中添加了模块。
inject方法执行时没有任何错误。但是当我记录$ 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);
}
}]
};
});