Reputation: 61
I have read the docs and I see there is an update method. However I am not having any luck with it. I get "Cannot call method 'update' of undefined". I can however change update to 'add' and the function works. I am doing something wrong, I just don't know what..
Here is my code:
(function() {
'use strict';
angular.module('myApp').controller('MainCtrl',['$scope','angularFireCollection', function($scope, angularFireCollection) {
var url = 'https://myapp.firebaseio.com/genre';
$scope.genres = angularFireCollection(new Firebase(url), $scope, 'genres');
$scope.vote = function(){
this.artist.votes=this.artist.votes + 1;
$scope.genres.update(this); // this update is not working.
}
}]);
}).call(this);
Thanks for your help.
Upvotes: 0
Views: 563
Reputation: 7428
What is this
in the context of the function? You should call $scope.genres.update with either an item from the collection, or an ID. For example, this works:
$scope.genres = angularFireCollection(new Firebase(url), $scope, 'genres');
$scope.vote = function() {
var item = $scope.genres[0];
item.votes++;
$scope.genres.update(item);
}
Upvotes: 2