使用$ ocLazyLoad.inject方法注入角度模块

时间:2016-01-21 10:17:01

标签: angularjs oclazyload

尝试使用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);
            }

        }]
    };
});

0 个答案:

没有答案