I am developing an application with Firebase (1.0) and Angular (1.4). The problem I'm having is to ensure the data in view are synchronised with Firebase, while fetching denormalised data coming from two tables in Firebase:
The book table looks like this:
books: -JyDpkQrUozE3L7flpo: { title: "title1", author: {-JyDpkQrUozE3L7fl1x: true} }, -JyDpkQrUozE3L7flp1: { title: "title2", author: {-JyDptrrrezE3L7flKx: true} }, -JyDpkQrUozE3L7flp2: { title: "title3", author: {-JyDpkQrUozE3L7f222: true} }
The author table looks like this:
authors: -JyDpkQrUozE3L7flKx: { firstname: "jacques", lastname: "smith" }, -JyDptrrrezE3L7flKx: { firstname: "bill", lastname: "halley" }, -JyDpkQrUozE3L7f222: { firstname: "john", lastname: "ford" }
My controller looks like this:
.controller('booksController', ['$scope', '$firebaseArray', function($scope, $firebaseArray) { var ref = new Firebase("https://[PATH].firebaseio.com/"; $scope.bookList = $firebaseArray(ref.child('books')); $scope.authorList = $firebaseArray(ref.child('authors')); $scope.getAuthor = function(id) { return $scope.authorList.$getRecord(id); }; });
And my html looks like this:
<pre>
<p ng-repeat="book in books" ng-init="author = getAuthor(book.author)">
The author of {{book.title}} is {{author.firstName}} {{author.lastName}}.
</p>
</pre>
The desired output of the above should be: "The author of title1 is Jacques Smith. The author of title2 is Bill Halley ...". What I'm getting however is: "The author of title 1 is. The author of title2 is..." So the author in my html returns a blank.
Any idea?