2016-05-31 72 views
1

我只是角度上的初學者。是做這個小代碼。但它不工作.NG重複是例外顯示數組,但它不是。請幫助。 以下是代碼:angular.min.js:117錯誤:[ng:areq]

<!DOCTYPE html> 
<html data-ng-app=""> 
<head> 
    <title>Using Angulatjs directives and Data Binding</title> 

</head> 
<body> 
    <div data-ng-controller="SimpleController"> 
     Name: 
     <br> 
     <input type="text" data-ng-model="name" /> 
     <h3>Using ng-repeat and filters</h3> 
     <ul> 
      <li data-ng-repeat="cust in customers"> {{cust.name}}-{{cust.city}} </li> 
     </ul> 
    </div > 
    <script type="text/javascript" src="angular.min.js"></script> 



    <script> 
     function SimpleController($scope) 
     { 
      $scope.customers= [ 
        {name:'John Smith',city:'Phoenix'}, 
        {name:'John Doe',city:'New York'}, 
        {name:'Jane Doe',city:'Sansfransico'} 
        ]; 
     } 
    </script> 
</body> 
</html> 

[

我越來越對console.Screen拍下面的錯誤連接了。

angular.min.js:117錯誤:[NG:AREQ] http://errors.angularjs.org/1.5.5/ng/areq?p0=SimpleController&p1=not%20a%20function%2C%20got%20undefined 在錯誤(天然) 在文件:///home/shallow/60/angular.min.js:6:412 在QB (file:///home/shallow/60/angular.min.js:23:157) at Pa(file:///home/shallow/60/angular.min.js:23:244) at file :///home/shallow/60/angular.min.js:89:77 at O(file:///home/shallow/60/angular.min.js:72:75) at n(file: (文件:///home/shallow/60/angular.min.js:64:7) at g(file:///home/shallow/60/angular.min.js:58:305) at g(file: ///home/shallow/60/angular.min.js:58:322) at g(file:///home/shallow/60/angular.min.js:58 :322)(匿名函數)@ angular.min.js:117

截圖:

[1]: http://i.stack.imgur.com/CYbHp.png 

回答

0

angular正在使用什麼版本??。您的代碼適用於angular 1.3.0。角度的更新版本不允許聲明全局函數。這裏是你的代碼版本的工作plunker。

http://plnkr.co/edit/aDhWAC2YFoH64Srr4oUV?p=preview

我使用的角度1.3.0 CDN。

總體代碼:

<!DOCTYPE html> 
<html data-ng-app=""> 

    <head> 
    <script src="https://code.angularjs.org/1.3.0-beta.5/angular.js"></script> 
    </head> 
<body> 
    <div data-ng-controller="SimpleController"> 
     Name: 
     <br> 
     <input type="text" data-ng-model="name" /> 
     <h3>Using ng-repeat and filters</h3> 
     <ul> 
      <li data-ng-repeat="cust in customers"> {{cust.name}}-{{cust.city}} </li> 
     </ul> 
    </div > 
    <script> 
     function SimpleController($scope) 
     { 
      $scope.customers= [ 
        {name:'John Smith',city:'Phoenix'}, 
        {name:'John Doe',city:'New York'}, 
        {name:'Jane Doe',city:'Sansfransico'} 
        ]; 
     } 
    </script> 
</body> 

</html> 
+0

感謝很多:) –

0

你爲什麼不穿上data-ng-app屬性值來命名一樣myApp

主要模塊然後,在腳本標籤中定義控制器。 控制器應該屬於您之前在HTML標記中定義的主要模塊。

<!DOCTYPE html> 
<html data-ng-app="myApp"> 
<head> 
    <title>Using Angulatjs directives and Data Binding</title> 

</head> 
<body> 
    <div data-ng-controller="SimpleController"> 
     Name: 
     <br> 
     <input type="text" data-ng-model="name" /> 
     <h3>Using ng-repeat and filters</h3> 
     <ul> 
      <li data-ng-repeat="cust in customers"> {{cust.name}}-{{cust.city}} </li> 
     </ul> 
    </div > 
    <script type="text/javascript" src="angular.min.js"></script> 
    <script> 
     angular.module('myApp', []) 
      .controller('SimpleController', SimpleController); 

     function SimpleController($scope) 
     { 
      $scope.customers= [ 
        {name:'John Smith',city:'Phoenix'}, 
        {name:'John Doe',city:'New York'}, 
        {name:'Jane Doe',city:'Sansfransico'} 
      ]; 
     } 
    </script> 
</body> 
</html> 
相關問題