learn - AngularJS Firebase $ add no es una función
learn angular 6 (1)
Intento llevar un nuevo registro a mi Firebase. Pero cada vez que recibo un error de consola como este:
$scope.contacts.$add is not a function
Aquí está mi código:
app.controller(''contactsCtrl'',[''$scope'',''$firebaseObject'',function($scope,$firebaseObject){
var ref = new Firebase("https://<database_details>.firebaseio.com/contacts");
$scope.contacts = $firebaseObject(ref)
$scope.addContact = function(){
$scope.contacts.$add({
name: $scope.name,
address: $scope.address,
telephone: $scope.telephone,
company: $scope.company,
email: $scope.email
}).then(function(ref){
var id = ref.key();
console.log(''contact added with Id: '' + id);
});
};
}]);
Debería usar $firebaseArray
lugar de $firebaseObject
app.controller(''contactsCtrl'',''$scope'',''$firebaseArray'',function($scope,$firebaseArray){
var ref = new Firebase("https://<database_details>.firebaseio.com/contacts");
$scope.contacts = $firebaseArray(ref)
$scope.addContact = function(){
$scope.contacts.$add({
name: $scope.name,
address: $scope.address,
telephone: $scope.telephone,
company: $scope.company,
email: $scope.email
}).then(function(ref){
var id = ref.key();
console.log(''contact added with Id: '' + id);
});
};
}]);