angular.js - items.query is not a function這是怎么回事
問題描述
<p ng-app='myApp'> <p ng-controller='firstcontroller'><h1>Shop!</h1><table> <tr ng-repeat='item in items'></tr> <td>{{item.title}}</td> <td>{{item.description}}</td> <td>{{item.price | currency}}</td> </tr></table> </p></p> <script>var app = angular.module('myApp', []);app.factory(’items’, function() { var items = {}; items.query = function() {return [{ title: ’Paint pots’, description: ’Pots full of paint’, price: 3.95}, { title: ’Polka dots’, description: ’Dots with polka’, price: 2.95}, { title: ’Pebbles’, description: ’Just little rocks’, price: 6.95}]; } return items;})app.controller(’firstcontroller’,[’$scope’,’items’,function($scope,items){ $scope.items=items.query();}])</script>
瀏覽可以正確運行代碼,但是不顯示數據。只顯示出
<p ng-app='myApp'> <p ng-controller='firstcontroller'><h1>Shop!</h1>{{items}} </p></p>
代碼更改成這樣,可以顯示出數據,說明數據已經綁定成功了,為什么使用這段代碼,無法顯示數據?
<table> <tr ng-repeat='item in items'></tr> <td>{{item.title}}</td> <td>{{item.description}}</td> <td>{{item.price | currency}}</td> </tr> </table>
初學Angular,如果,有哪里不正確,請各位指出。
問題解答
回答1:第一個tr后面多了一個/tr吧 這樣里面沒東西,所以已經repeat了只是repeat出了一堆空
相關文章:
1. css - 如何把一個視圖放在左浮動定位的視圖的上面?2. python的正則怎么同時匹配兩個不同結果?3. php多任務倒計時求助4. javascript - axios請求回來的數據組件無法進行綁定渲染5. javascript - vue中怎么使用原生js插件6. MySQL的聯合查詢[union]有什么實際的用處7. javascript - jquery怎么讓a標簽跳轉后保持tab的樣式8. css - 子元素跑到父元素外面9. javascript - 小demo:請教怎么做出類似于水滴不斷擴張的效果?10. javascript - 請問下面代碼中的...是擴展運算符還是操作運算符?這樣寫是什么意思?
