angular.js - items.query is not a function這是怎么回事
問(wèn)題描述
<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>
瀏覽可以正確運(yùn)行代碼,但是不顯示數(shù)據(jù)。只顯示出
<p ng-app='myApp'> <p ng-controller='firstcontroller'><h1>Shop!</h1>{{items}} </p></p>
代碼更改成這樣,可以顯示出數(shù)據(jù),說(shuō)明數(shù)據(jù)已經(jīng)綁定成功了,為什么使用這段代碼,無(wú)法顯示數(shù)據(jù)?
<table> <tr ng-repeat='item in items'></tr> <td>{{item.title}}</td> <td>{{item.description}}</td> <td>{{item.price | currency}}</td> </tr> </table>
初學(xué)Angular,如果,有哪里不正確,請(qǐng)各位指出。
問(wèn)題解答
回答1:第一個(gè)tr后面多了一個(gè)/tr吧 這樣里面沒(méi)東西,所以已經(jīng)repeat了只是repeat出了一堆空
相關(guān)文章:
1. docker鏡像push報(bào)錯(cuò)2. javascript - URL中有#號(hào)如何來(lái)獲取參數(shù)啊? nodejs3. angular.js - angular內(nèi)容過(guò)長(zhǎng)展開(kāi)收起效果4. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問(wèn)題5. docker不顯示端口映射呢?6. docker容器呢SSH為什么連不通呢?7. 關(guān)于docker下的nginx壓力測(cè)試8. 新手求教python3如何把dict循環(huán)寫(xiě)入csv文件(在進(jìn)行爬蟲(chóng)時(shí)遇到的問(wèn)題)?9. python - 想要看Exception實(shí)現(xiàn)的源碼在什么位置?10. python - Django表單Form.save()問(wèn)題
