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>
瀏覽可以正確運行代碼,但是不顯示數(shù)據(jù)。只顯示出
<p ng-app='myApp'> <p ng-controller='firstcontroller'><h1>Shop!</h1>{{items}} </p></p>
代碼更改成這樣,可以顯示出數(shù)據(jù),說明數(shù)據(jù)已經(jīng)綁定成功了,為什么使用這段代碼,無法顯示數(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,如果,有哪里不正確,請各位指出。
問題解答
回答1:第一個tr后面多了一個/tr吧 這樣里面沒東西,所以已經(jīng)repeat了只是repeat出了一堆空
相關(guān)文章:
1. java - spring boot 如何打包成asp.net core 那種獨立應(yīng)用?2. datetime - Python如何獲取當前時間3. android - SwipeRefreshLayout5.0以下不兼容4. java - 在用戶不登錄的情況下,用戶如何添加保存到購物車?5. 安全性測試 - nodejs中如何防m(xù)ySQL注入6. html - eclipse 標簽錯誤7. javascript - nginx反向代理靜態(tài)資源403錯誤?8. python文檔怎么查看?9. javascript - 關(guān)于apply()與call()的問題10. javascript - webpack 分割加載代碼后,react 界面不更新
