Related to this question , I need to be able to get an item from the collection as a Firebase link, i.e. given $firebaseArrayI need $firebaseObject, pointing to one of its elements. Unlike this example, I canβt just hardcode the path to the array and take it from there, because the location of the array will be different. And I cannot use $firebaseArray.$getRecord()either the object provided by mine ng-repeat, which follows array.$save(), because I may need push()for this element.
So, I settled on this reusable approach:
In the service:
function selectElement(array, element) {
var obj = $firebaseObject(array.$ref().child(element.$id));
return obj;
}
In the controller:
function onItemClicked(e) {
vm.selected = dataservice.selectElement(vm.observations, e);
}
In the template:
<div class="list-item" ng-repeat="o in vm.observations" ng-click="vm.onItemClicked(o)">
The first line selectElementthrows an error:array.$ref(...).child is not a function at Object.selectElement
array , , array.$ref() :
Y {k: Ji, path: P, n: Ce, pc: true}
. ? Firebase ?