你的位置:首页 > Java教程

[Java教程]angular.js写法不规范导致错误


以下写法:没有明确指定module和controller,写法不规范. 更改angular.js版本会出bug.

 

 1 <html ng-app> 2 <head> 3   <title>1.0.1-1.5版本间的差异</title> 4   <script src="http://www.cnblogs.com//js/angular-1.0.1.min.js"></script> <!--可以正常显示--> 5   <!--<script src="http://www.cnblogs.com//js/angular.min.js"></script> 1.5版本 显示不了--> 6   <script> 7      8     /* phones.js 9       [10       {11         "name": "Nexus S",12         "snippet": "Fast just got faster with Nexus S.",13         "age": 0,14         "imageUrl": "/img/01.png",15         "id":116       },17       {18         "name": "Motorola XOOM™ with Wi-Fi",19         "snippet": "The Next, Next Generation tablet.",20         "age": 1,21         "imageUrl": "/img/02.png",22         "id": 223       },24       {25         "name": "MOTOROLA XOOM™",26         "snippet": "The Next, Next Generation tablet.",27         "age": 2,28         "imageUrl": "/img/03.png",29         "id": 330       }31     ]32     */33     function PhoneListCtrl($scope, $http) {34       $http.get('/html/angular/json/phones.js').success(function (data) {35         $scope.phones = data;36       });37     }38   </script>39   <link href="http://www.cnblogs.com//js/bootstrap-3.3.5-dist/css/bootstrap.min.css" rel="stylesheet" />40 </head>41 <body >42   <div class="container-fluid">43     <div class="row" ng-controller="PhoneListCtrl">44 45       <ul>46         <li ng-repeat="phone in phones">47           <a href="#{{phone.id}}">{{phone.name}}</a>48           <p>{{phone.snippet}}</p>49         </li>50       </ul>51 52 53     </div>54   </div>55 </body>56 </html>

 

附学习地址:

a.angularJS中文社区

b.angularJS官网

 

下篇:写个规范的...