AngularJS Firebase $ add不是一个函数 [英] AngularJS Firebase $add is not a function
本文介绍了AngularJS Firebase $ add不是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ scope.contacts。$ add不是一个函数
以下是我的代码:
app.controller('contactsCtrl',['$ scope','$ firebaseObject',function($ scope,$ firebaseObject){
var ref = new Firebase(https:// < database_details> .firebaseio.com / contacts);
$ scope.contacts = $ firebaseObject(ref)
$ b $ scope.addContact = function(){
$ b $ scope.contacts。$ add({
名称:$ scope.name,
地址:$ scope.address,
电话:$ scope.telephone,
公司:$ scope.company,
email:$ scope.email
})。then(function(ref){
var id = ref.key();
console.log('contact with Id:'+ id);
});
};
}] );
解决方案
您应该使用 $ firebaseArray 代替
$ firebaseObject
app。控制器('contactsCtrl','$ scope','$ firebaseArray',函数($ 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,
地址:$ scope.address,
电话:$ scope.telephone,
公司:$ scope.company,
电子邮件:$ scope.email
)}然后(函数(ref){
var id = ref.key();
console.log('contact with Id:'+ id);
});
};
}]);
I try to push a new record to my Firebase. But everytime I receive a console error like this:
$scope.contacts.$add is not a function
Here is my code:
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);
});
};
}]);
解决方案
You should use $firebaseArray
instead of $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);
});
};
}]);
这篇关于AngularJS Firebase $ add不是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文