AngularFire - 如何定义项目ID与NG-重复子模板? [英] AngularFire - How to define item ID for child template with ng-repeat?
问题描述
也许我的问题似乎很容易解决,但我这个问题,因为很多的时间:当我在我的仪表板来的,我的火力地堡数据库的所有数据都是可见的(含伍重复)。
但我不能发现选择一个特定的项目,看到另一页他详细的解决方案。
Maybe my issue seems easy to resolve, but I've this problem since a lot of hours : When I'm in my dashboard, all data of my Firebase database are visible (With Ng-repeat). But I can't found a solution for choose one specific item and see his details in another page.
我已经测试这种方法的HTML(这是一个例子):
I've test this method in HTML (This is an example) :
<div ng-repeat="post in posts">
<div class="card" ng-href="#/post/">">
<h1>{{post.title}}</h1>
<p>{{post.content}}</p>
</div>
</div>
在应用JS:
.state('tabpost', {
url: 'tabpost/id',
templateUrl: 'templates/tab-post.html',
controller: 'PostCtrl'
})
在服务JS(中邮厂):
In Service JS (in Post Factory) :
myApp.factory("Post", ["$firebaseArray", "$firebaseObject", function($firebaseArray, $firebaseObject) {
var postRef = new Firebase('https://myApp.firebaseio.com/Posts/');
var userRef = new Firebase('https://myApp.firebaseio.com/Users/');
var posts = $firebaseArray(postRef);
var Post = {
all: posts,
get: function (postKey){
var postId = $firebaseObject(postRef);
return $firebaseObject(eventRef.child('Posts').child(postId).child(userid));
}
,
add: function (post){
var postId = $firebaseArray(postRef, userRef);
event.userid = userRef.getAuth();
return postId.$add(post);
}
}
return Post;
}]);
我PostCtrl:
My PostCtrl :
myApp.controller('PostCtrl', ['$ionicFrostedDelegate', '$ionicScrollDelegate','$state','$scope', 'Post', 'Auth', '$firebaseObject', '$firebaseArray', function($ionicFrostedDelegate, $ionicScrollDelegate, $state,$scope, Post, Auth, $firebaseObject, $firebaseArray) {
var PostRef = new Firebase("https://myApp.firebaseio.com/Posts");
$scope.posts = Post.all;
$scope.post = {'title': '', 'content': ''};
$scope.auth = Auth;
PS:花了16小时试了一堆教程大多是过时的,我相信该解决方案不能简单
PS : It took 16 hours to try a bunch of tutorials mostly obsolete , and I am sure that the solution can not be that simple.
我已经发布了两个类似的问题,昨天和今天上午,但每一个提出的解决方案都没有奏效。我将非常感激谁也帮我出这个僵局的人。
I already posted two similar issues yesterday and this morning but each of the proposed solutions have not worked . I would be immensely grateful to the person who would help me out of this impasse .
我还是有一点麻烦的jsfiddle答应我会学会使用它,一旦我已经解决了这个问题。
I still have a little trouble with jsFiddle promised I would learn to use it once I would have solved this problem.
感谢你给我时间
推荐答案
您可以使用路由提供商这样做。我用我的应用程序,它的伟大工程。
you can use route provider to do that. I used that for my application and it works great.
myApp.config( ['$routeProvider', function($routeProvider){
$routeProvider.
when('tabpost', {
templateUrl: 'tabpost/id',
controller: 'PostCtrl'
});
}]);
这篇关于AngularFire - 如何定义项目ID与NG-重复子模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!