Complications with three-way data binding in AngularFire

27 views
Skip to first unread message

JD

unread,
Mar 27, 2015, 3:38:35 PM3/27/15
to fireba...@googlegroups.com
Good day, I am having some pretty heavy complications with using an ng-click; linked to a controller and calling a service from there in a separate js file. The .factory Service function is one of many inside of services.js which use the arguments: userId, itemType, itemId, and rating, and yet, this particular function uses these arguments to create a directory reference to .set to firebase. All of the arguments I previously mentioned though, are going to firebase as undefined. I believe that I need assistance in how to define the variables. Here is all of the necessary code, and thank you.

The first input of the html:

  <div class="ratings form-group" ng-controller="rateCtrl">
  <input id="rate1" ng-click="rate(userId, itemType, itemId, rating)" value="1" class="rate rate1 form-control" title="1" type="radio" name="rate"/>

The controller:

.controller('rateCtrl', ['$scope', 'ratingsService', function($scope, ratingsService) {
    rate();
}
])

The .factory service:

  .factory('ratingsService', function() {

    return {

      rate: function(userId, itemType, itemId, rating) {
        // @todo Construct a new promise that resolves when both Firebase operations have been performed.
        console.log("SUCCESS!");
        $firebase( new Firebase(dvUrl + '/users/' + userId + '/ratings/' + itemType + '/' + itemId) ).$set(rating);
        $firebase( new Firebase(dvUrl + '/' + itemType + '/' + itemId + '/ratings/' + userId) ).$set(rating);

      }

  })

Kato Richardson

unread,
Mar 27, 2015, 6:48:08 PM3/27/15
to fireba...@googlegroups.com
Hey JD,

Nothing in your controller puts a rate function into $scope, so it couldn't be accessed from the page in ng-click. rate() is called in the controller but doesn't exist (not sure what this is intended to do since it calls rate without any arguments; explains why they are undefined).

Something like $scope = ratingsService.rate is probably more what you had in mind.

Looks like you're missing some fundamentals about Angular here, and their new docs site may be the right place to get up to speed.

Also, this is using an outdated version of AngularFire and you should consider upgrading to the stable release.

Cheers,
Kato



--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/3354bb3e-4459-492d-9c57-190d61823959%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages