shubgpt shubgpt - 2 months ago 14x
AngularJS Question

AngularFire searching key node and assign to variable

I 'm working on my AngularFire project. I've a database something like this What I'm doing is first searching the key like the dinosaurs child such as "linhenykus" and storing its keys and values to other $scope variable.

my code in controller

var ref = new Firebase("" + "/" + $scope.dinoID); //$scope.dinoID is variable containg dino keys

$scope.detRef = $firebaseArray(ref);

I'm getting the output like


How to fetch the keys and values?


Use ngRepeat directive, as below:

<tr ng-repeat="obj in array track by $index">

To filter the array you can use the filter of Angular:

<tr ng-repeat="obj in array | filter: criteria track by $index">

Here's an example:

(function() {
    .module('app', [])
    .controller('MainCtrl', MainCtrl);

  MainCtrl.$inject = ['$scope', '$filter'];

  function MainCtrl($scope, $filter) {
    $scope.criteria = {};
    $scope.array = [  

    $scope.getObj = function(value, id) {
      $scope.obj = $filter('filter')($scope.array, {
        "$value": value,
        "$id": id

     $scope.getObj("theropoda", "order");
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
<!DOCTYPE html>
<html ng-app="app">

  <script src=""></script>

<body ng-controller="MainCtrl">
  <input type="text" placeholder="Search by value" ng-model="criteria.$value">
  <input type="text" placeholder="Search by id" ng-model="criteria.$id">
  <!-- Note that this button is just as an example to change the object displayed below -->
  <button type="button" ng-click="getObj()">Change the value of object</button>
  Obj: <span ng-bind-template="Value: {{obj.$value}}, Id: {{obj.$id}}"></span>
  <table width="100%">
      <tr ng-repeat="obj in array | filter: criteria track by $index">
        <td ng-bind="obj.$value"></td>
        <td ng-bind="obj.$id"></td>
        <td ng-bind="obj.$priority"></td>