2015-11-17 41 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

相關問題