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. mysql - 千万级数据表如何有效的变更字段?2. php - SQL 一条语句查询出文章和对应的文章标签3. mysql多表查询4. 下载32位vc9和11、14运行库时解压错误5. php mysql数据库 产品分类与产品详情应该怎么做?6. 新建index文件夹,然后把controller 以及文件index.php放入index文件夹。修改htaccess文件为扩展访问。但是访问的时候提示页面错误!请稍后再试。PHP版本正常,请老师解答7. php+mysql 高并发 根据id 循环下载数据如何避免重复 (接口)8. java - mysql缓存问题9. java - 触发器使两张表同时更新10. 请问一下,图片上传成功,但是后台对应文件夹里面却没有图片,这是什么原因?(已部署到服务器)

网公网安备