2015-11-17 20 views
1

我是Angular Programming的新手,我发现了一个关于使用ocLazyLoad的问题。ocLazyLoad不加载控制器,如何解决它?

首先,我将ocLazyLoad导入到我的应用程序中。但控制台发生这些错误。

Error: [ng:areq] Argument 'ABController' is not a function, got undefined

我该怎么做,因为我需要处理控制器的一些后端数据。假设控制台需要显示“123”。这是我的代码。

的Index.html

<script src="https://code.jquery.com/jquery-1.11.2.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.js"></script> 
<script src="js/main.js"></script> 
<script src="../../dist/ocLazyLoad.js"></script> 

<body> 
    <div id="example" ng-app="LazyLoadTest" ng-controller="TestController"> 
     <div ng-controller="ABController"></div> 
    </div> 
    <script> 
      app.controller("TestController", function($scope, $ocLazyLoad, $compile) { 
       $ocLazyLoad.load("js/test.js").then(function() { 
        console.log('loaded!!'); 
       }, function(e) { 
        console.log('errr'); 
       }) 
      }); 
    </script> 
</body> 

main.js

var app = angular.module("LazyLoadTest", ["oc.lazyLoad"]); 

test.js

app.controller('ABController', function($scope){ console.log("123"); }); 

回答

1

如果我没有忽略任何细节: 你忘了,包括测试。 js into your index.html ...

+0

哦,THX,仅此而已。 = D – tommychoo

+6

你是认真的吗?他正在尝试使用$ ocLazyLoad。如果你将'test.js'加载到你的index.html中,那就好像不使用$ ocLazyLoad – RicardoGonzales

1

尝试使用

angular.module("LazyLoadTest").controller('ABController', function($scope){ console.log("123"); }); 

在test.js

相关问题