使用angularFire隐式同步在ng-repeat内访问Firebase唯一ID [英] Access Firebase unique ids within ng-repeat using angularFire implicit sync

查看:161
本文介绍了使用angularFire隐式同步在ng-repeat内访问Firebase唯一ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 angularFire 隐式数据同步从Firebase获取对象列表,并且想要将它们唯一的ID(用于网址)与其他数据属性使用 ng-repeat 。我可以通过如何使用 ng-repeat 中的对象ID来返回 angularFire angularFireCollection 的成员是否拥有 $ id 属性的方式?如果不是,那么完成这个的正确方法是什么?假设代码(不起作用):

控制器:

  myApp.controller('ItemListCtrl',['$ scope','angularFire',
function ItemListCtrl($ scope,angularFire){
var ref = new Firebase(firebaseUrl );
angularFire(ref,$ scope,'items');
}
]);

检视:

 < div ng-repeat =item in items> 
< a href =ng-href =#/ items / {{item.name()}}> {{item.text}}< / a>
< / div>


解决方案

我想所有你需要的是:

 < div ng-repeat =(name,item)in items> 
< a href =ng-href =#/ items / {{name}}> {{item.text}}< / a>
< / div>

anglularFire对象的行为就像普通的javascript对象一样。


I have a list of objects from Firebase using the angularFire implicit data sync, and I'd like to render their unique ids (for use in urls) along with the other data properties using ng-repeat. Can I make angularFire return in such a way that I have access to the object ids within ng-repeat, the same way that members of an angularFireCollection have an $id property? If not, what is the right way to accomplish this? Hypothetical code (that doesn't work):

Controller:

myApp.controller('ItemListCtrl', ['$scope', 'angularFire',
  function ItemListCtrl($scope, angularFire) {
    var ref = new Firebase(firebaseUrl);
    angularFire(ref, $scope, 'items');
  }
]);

View:

<div ng-repeat="item in items" >
  <a href="" ng-href="#/items/{{item.name()}}">{{item.text}}</a>
</div>

解决方案

I think all you need is:

<div ng-repeat="(name, item) in items">
  <a href="" ng-href="#/items/{{name}}">{{item.text}}</a>
</div>

The anglularFire object behaves just like a normal javascript object.

这篇关于使用angularFire隐式同步在ng-repeat内访问Firebase唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆