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. css3 - css做動(dòng)畫效果2. javascript - vue-cli proxyTable怎么配置3. java - 部署web項(xiàng)目時(shí)無(wú)法省略項(xiàng)目名?4. java-ee - JAVA8 lambdas表達(dá)式 改變外面變量的值5. java - 安裝visibroker時(shí)報(bào)錯(cuò)6. python - nginx 小白, nginx 啟動(dòng)后 80 端口無(wú)法訪問(wèn)7. java - JPA連接數(shù)據(jù)庫(kù),一段時(shí)間沒(méi)有數(shù)據(jù)操作會(huì)關(guān)閉連接,再次訪問(wèn)就會(huì)拋出異常,如何解決?8. windows - idea提示錯(cuò)誤:java.lang.ClassNotFoundException: com.mysql.jdbc.Driver9. java - svn導(dǎo)下來(lái)的項(xiàng)目,web-inf下怎么沒(méi)有l(wèi)ib文件呀?10. javascript - 關(guān)于nodejs處理并發(fā)的一點(diǎn)小疑惑
