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. python - Win7調用flup報錯’module’ object has no attribute ’fromfd’2. 網頁爬蟲 - Python 爬蟲中如何處理驗證碼?3. mysql - 分庫分表、分區、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處4. Python如何播放還存在StringIO中的MP3?5. javascript - 請教如何獲取百度貼吧新增的兩個加密參數6. mysql 一個sql 返回多個總數7. python - 我在使用pip install -r requirements.txt下載時,為什么部分能下載,部分不能下載8. mysql - 如何減少使用或者不用LEFT JOIN查詢?9. Python爬蟲如何爬取span和span中間的內容并分別存入字典里?10. python - 編碼問題求助
