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. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?2. javascript - 在 vue里面用import引入js文件,結果為undefined3. python沒入門,請教一個問題4. php如何獲取訪問者路由器的mac地址5. html5 - input type=’file’ 上傳獲取的fileList對象怎么存儲于瀏覽器?6. 小程序怎么加外鏈,語句怎么寫!求救新手,開文檔沒發現7. 求教一個mysql建表分組索引問題8. node.js - 用nodejs 的node-xlsx模塊去讀取excel中的數據,可是讀取出來的日期是數字,請問該如何讀取日期呢?9. sql語句如何按or排序取出記錄10. javascript - vue-resource中如何設置全局的timeout?
