Thinkster.io第3期 [英] Thinkster.io Chapter 3 Issue
问题描述
我试图让本教程的工作:
I am trying to get this tutorial to work:
<一个href=\"http://www.thinkster.io/angularjs/S2MxGFCO0B/3-communicating-with-a-server-using-a-service-and-resource\" rel=\"nofollow\">http://www.thinkster.io/angularjs/S2MxGFCO0B/3-communicating-with-a-server-using-a-service-and-resource
我白手起家3次启动。 (删除整个Linux的虚拟机),我似乎无法得到这code拉下什么是火力点。它节省了完美火力点,我可以看到它,但不显示任何内容。
I have started from scratch 3 times. (Deleted the whole Linux VM) I cannot seem to get this code to pull down what is in firebase. It saves to firebase perfectly and I can see it, but nothing is displayed.
code:
/app/views/posts.html:
/app/views/posts.html:
div ng-repeat="(postId, post) in posts">
<a href="{{post.url}}">{{post.title}}</a>
<a ng-click="deletePost(postId)">delete</a>
</div>
<form ng-submit="submitPost()">
<input type ="text" ng-model="post.title" />
<input type ="text" ng-model="post.url" />
<input type ="submit" value="Add Post" />
</form>
/app/scripts/controllers/posts.js:
/app/scripts/controllers/posts.js:
'use strict';
app.controller('PostsCtrl', function($scope, Post) {
$scope.posts = [];
$scope.post = {url: 'http://', title: ''};
$scope.submitPost = function (){
Post.save($scope.post, function (ref) {
$scope.posts[ref.name] = $scope.post;
$scope.post = {url: 'http://', title: ''};
});
$scope.post = {url: 'http://', title: ''};
};
$scope.deletePost = function (postId) {
Post.delete({id: postId}, function (){
delete $scope.posts[postId];
});
};
});
/app/scripts/services/post.js:
/app/scripts/services/post.js:
'use strict';
app.factory('Post', function ($resource){
return $resource('https://xxxxxxxxx.firebaseio.com/posts/:id.json');
});
我相当有信心,这个问题是在这3个文件之一。任何帮助将是AP preciated。
I am fairly confident that the problem is in one of these 3 files. Any help would be appreciated.
推荐答案
在您的code你使用像一个文字对象的数组,该NG重复指令不能显示结果。
in your code you use an array like a literal object, the ng-repeat directive cant display the result.
数组索引必须是整数,您使用的字符串:
An array index must be an integer and you use a string :
Post.save($scope.post, function (ref) {
$scope.posts[ref.name] = $scope.post;
尝试类似的东西。
try something like that
$scope.posts.push($scope.post);
或只是声明$ scope.posts变量作为文字对象
or just declare the $scope.posts variable as a literal object
$scope.posts = {};
希望它会帮助你。
Hope it will help you
这篇关于Thinkster.io第3期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!