Friday 15 February 2013

firebase - AngularFire $add—TypeError: undefined is not a function -



firebase - AngularFire $add—TypeError: undefined is not a function -

when seek substitute $add push, error.

typeerror: undefined not function @ scope.$scope.sendcomment (http://localhost:9000/scripts/controllers/post.js:22:38) @ http://localhost:9000/bower_components/angular/angular.js:10847:21 ...

here's controller @ post.js

16 $scope.sendcomment = function () { 17 var newcomment = { 18 user: $scope.currentuser, 19 text: $scope.currenttext 20 21 }; 22 var promise = commentservice.add(newcomment); 23 promise.then(function(name) { 24 console.log(name); 25 }); 26 };

here's service (the problematic add together function toward bottom)

(function(angular) { 'use strict'; angular.module('codesapp').service('commentservice', function(fburl, $q, $firebase) { var commentref = new firebase(fburl).child('comments'); var firecomment = $firebase(commentref); homecoming { childadded: function childadded(limitnumber, cb) { commentref.startat().limit(limitnumber).on('child_added', function(snapshot) { var val = snapshot.val(); cb.call(this, { user: val.user, text: val.text, name: snapshot.name() }); }); }, add: function addcomment(comment) { homecoming firecomment.$add(comment); }, ....

i've been stuck on night. help hugely appreciated! thanks!

$firebase(commentref) gets half way firebase array can phone call $add().

you must additionally phone call $asarray() on homecoming value of $firebase(commentref) so:

var firecommentarray = $firebase(commentref).$asarray();

then can

firecommentarray.$add(comment)

firebase angularfire

No comments:

Post a Comment