I have been playing with AngularFire for several days, and I wonder if I can just try, which in the end is a bad use case. I will be doing live chat / presence on my site, so this part is useful. This part I'm working on is I don’t know.
So, I have a registration form. When users register, they must select a color from the drop-down list. I have a list stored in an array in Firebase.
I am trying to maintain a fairly strict MVC setup, so I have each controller in its own file, as well as each corresponding service. The previous angular applications I wrote used a structure, and so far it has worked well.
What I can’t understand is the correct way to just read the list and populate it in the drop-down list.
In previous angular applications, there was just something like:
return $resource(URL + /colors);
So, in AngularFire, I used mainly this, which works, buuuuutttt:
getColors: function($scope) {
syncData('usergen/colors').$bind($scope, 'colorsRaw').then(function() {
var keys = $scope.colorsRaw.$getIndex();
angular.forEach(keys, function(key) {
var color = {label: $scope.colorsRaw[key], value: $scope.colorsRaw[key]};
$scope.data.colors.push(color);
});
$scope.data.color = $scope.data.colors[Math.floor(Math.random() * $scope.data.colors.length)];
});
}
Now, of course, that I absolutely HATE: why do I have to go around this area? It seems I can’t get getColor () to return a regular array of objects {name: "Blue", value: "Blue"}. Not only do I need to pass $ scope around, I cannot set the drop to a random value unless I do this in the service. Bad bad bad. I don’t want to pass the Ctrl area to the service at all, and I certainly don’t want to update the variables of the $ Ctrl variable from the service.
? Firebase , , . , , .
, Firebase/AngularFire, $var?
.