I'm try to write something to firebase from directive
This is my directive [UPDATED]:
angular.module('MyApp.directives').directive('score', function() {
return {
restrict: "E",
scope: {
},
templateUrl: 'dashboard/score.html',
controller: ['$scope', function ($scope) {
}],
link: function(scope, element, attrs, controller, firebase) {
var eventsRef = new Firebase('https://URL.firebaseio.com/');
scope.event_id = attrs.index;
//Score counter
scope.Score = [0, 0];
scope.add_btn = function(num) {
scope.Score[num]++;
};
scope.dist_btn = function(num) {
if (scope.Score[num] > 0) {
scope.Score[num]--;
} else {
num = 0;
}
};
scope.setPrediction = function () {
eventsRef.child('/'+scope.event_id+'/').update(scope.Score);
}
}
}
});
And it's throw error:
FIREBASE INTERNAL ERROR: Server Error: ClientId[7373865]:ErrorId[2]: Error on incoming message
Ok I realize wats happend. Firebase don;t like to post arrays without key's
This code is working:
angular.module('MyApp.directives').directive('score', function() {
return {
restrict: "E",
scope: {
},
templateUrl: 'dashboard/score.html',
controller: ['$scope', function ($scope) {
}],
link: function(scope, element, attrs, controller, firebase) {
var eventsRef = new Firebase('https://sportsbettr2.firebaseio.com/events');
scope.event_id = attrs.index;
//Score counter
scope.Score = [0, 0];
scope.add_btn = function(num) {
scope.Score[num]++;
};
scope.dist_btn = function(num) {
if (scope.Score[num] > 0) {
scope.Score[num]--;
} else {
num = 0;
}
};
scope.setPrediction = function () {
eventsRef.child('/'+scope.event_id+'/').update({
"score": scope.Score
});
}
}
}
});