I am trying to get three way data binding using firebase and angularfire. You can see what I have in Plunker: http://plnkr.co/edit/RGA4jZK3Y6n4RkPCHK37
app.js :
angular.module('ideaBattle', ["firebase"]);
services
angular .module('ideaBattle') .constant('FBURL', 'https://ideabattle.firebaseio.com/') .service('Ref', ['FBURL', Firebase]) .factory('dataBank', function(Ref, $firebase) { return $firebase(Ref).$asArray(); });
controller :
angular .module('ideaBattle') .controller('ideaListCtrl', displayIdeas); displayIdeas.$inject = ['dataBank']; function displayIdeas(dataBank){ var vm = this; vm.ideas = dataBank; vm.upVote = function(idea){ vm.ideas[idea.id].votes++; }; }
HTML
<div ng-controller="ideaListCtrl as vm"> <div ng-repeat="idea in vm.ideas | orderBy: '-votes'"> <div> <h2>{{idea.name}}</h2> <p>{{idea.desc|limitTo: 190}}</p> <span class="btn" ng-click="vm.upVote(idea)">Vote! <span class="badge"> {{idea.votes}}</span></span> </div> </div> </div>
Version for plunger: http://plnkr.co/edit/RGA4jZK3Y6n4RkPCHK37
What he does is he gets the data from firebase and displays it correctly, but when I click the button to call the upVote function, it only updates locally. I know why it only works locally, but I don't know how to make it also updatable in firebase.
I tried with $ bindTo, but from what I understand requires $ scope to work, and I'm trying to use the "Controller as vm" template without inserting $ scope.
Can someone tell me how to bite this?
zorza source share