0

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.

1 Answer 1

2

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);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank You. "this" didn't seem right to me, but I thought that was the same as your item above in essence. I had to keep the this.artist.votes++ to update my $scope.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.