2016-05-31 42 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> 
相关问题