使用angularFire隐式同步在ng-repeat内访问Firebase唯一ID [英] Access Firebase unique ids within ng-repeat using angularFire implicit sync
问题描述
我使用 控制器: 检视: 我想所有你需要的是: anglularFire对象的行为就像普通的javascript对象一样。 I have a list of objects from Firebase using the Controller: View:
I think all you need is: The anglularFire object behaves just like a normal javascript object. 这篇关于使用angularFire隐式同步在ng-repeat内访问Firebase唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! angularFire
隐式数据同步从Firebase获取对象列表,并且想要将它们唯一的ID(用于网址)与其他数据属性使用 ng-repeat
。我可以通过如何使用 ng-repeat
中的对象ID来返回 angularFire
$ 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>
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):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>