2014-09-19 44 views
0

我需要一些幫助的人。只需要學習角度,我就是這樣設置自己的。錯誤:[ng:areq] http://errors.angularjs.org/1.2.25/ng/areq?

這是我的文件結構。 enter image description here

AboutController.js

function AboutController($scope){ 
    $scope.data = { 
     "data" : { 
      "name" : "nameku", 
      "email" : "email.com" 
     }, 
     "data" : { 
      "name" : "nameku2", 
      "email" : "email2.com" 
     } 
    } 
} 

about.html

<script type="text/javascript" src="controllers/AboutController.js"></script> 
<div ng-controller="AboutController"> 
    <ul ng-repeat="d in data"> 
     <li>{{d.name}}</li> 
    </ul> 
</div> 

的index.html

<html ng-app="TestingAngular"> 
<head> 
<title>TestingAngular Dashboard</title> 
</head> 
<script type="text/javascript" src="components/angular/angular.min.js"></script> 
<script type="text/javascript" src="components/angular-route/angular-route.min.js"></script> 
<script type="text/javascript" src="route.js"></script> 
    <body> 
     <div ng-view></div> 
    </body> 
</html> 

route.js

angular.module('TestingAngular', ['ngRoute']) 
    .config(function($routeProvider){ 
     $routeProvider 
     .when(
      '/about' , {templateUrl: 'views/about.html'} 
     ) 
     .when(
      '/contact' , {templateUrl: 'views/contact.html'} 
     ) 
     .when(
      '/' , {templateUrl: 'views/home.html'} 
     ); 
    }); 

我的問題是我得到這個錯誤。有沒有辦法,我希望它可以工作?

當我移動

<script type="text/javascript" src="controllers/AboutController.js"></script> 

的指數,它會工作。請糾正我,如果我在錯誤的道路很

錯誤:[NG:AREQ] http://errors.angularjs.org/1.2.25/ng/areq?p0=AboutController&p1=not%20aNaNunction%2C%20got%20undefined 在錯誤(原生)

+0

試圖聲明您的控制器'angular.module( 'TestingAngular')。控制器( 'AboutController',函數($ scope){});' – akn 2014-09-19 06:41:20

回答

3

AngularJS需要所有控制器,服務,指令和過濾器在登記config應用程序可以運行之前的階段。延遲加載不支持開箱即用。因此,你所有的腳本都必須在索引頁面中註冊,所以你做得很好。

對於延遲加載,你需要看一些自定義組件這樣的0​​https://github.com/ocombe/ocLazyLoad

https://github.com/nikospara/angular-require-lazy

+0

我明白了。謝謝(你的)信息。 – Snippet 2014-09-19 07:05:56

相關問題