The only interesting part is the getBuilding function, which takes a building index, gets its key, and creates a Firebase reference for the relative path of that particular building by calling the child function and passing in the key. Then we create a synchronized object for that building using $firebaseObject. BuildingsCtrl is very straightforward, so here’s the maybe more interesting BuildingCtrl:

app.controller('BuildingCtrl', ['$scope', '$routeParams', 'buildingSvc',
  function ($scope, $routeParams, buildingSvc) {

    var hasAnError = false;

    $scope.hasError = function () {
      return hasAnError;
    };

    if ($routeParams.buildingIndex !== null) {
      var index = parseInt($routeParams.buildingIndex);

      if (!isNaN(index)) {
        // create a three-way binding to our building as $scope.building
        buildingSvc.getBuilding(index).$bindTo($scope, "building");
      }
      else {
        hasAnError = true;
      }
    }
  }
]);

(dunebook\three-way-binding\building\building.ctl.js)