使用 angularFire 隐式同步在 ng-repeat 中访问 Firebase 唯一 ID [英] Access Firebase unique ids within ng-repeat using angularFire implicit sync
问题描述
我有一个使用 angularFire
隐式数据同步的 Firebase 对象列表,我想使用 呈现它们的唯一 ID(用于 url)以及其他数据属性>ng-repeat
.我可以让 angularFire
以这样一种方式返回,即我可以访问 ng-repeat
中的对象 ID,就像 angularFireCollection
的成员一样> 有 $id
属性?如果没有,实现这一目标的正确方法是什么?假设代码(不起作用):
控制器:
myApp.controller('ItemListCtrl', ['$scope', 'angularFire',函数 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>
我认为您只需要:
<a href="" ng-href="#/items/{{name}}">{{item.text}}</a>
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屋!