Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AngularJS Firebase$add不是一个函数_Angularjs_Firebase_Firebase Realtime Database_Angularfire - Fatal编程技术网

AngularJS Firebase$add不是一个函数

AngularJS Firebase$add不是一个函数,angularjs,firebase,firebase-realtime-database,angularfire,Angularjs,Firebase,Firebase Realtime Database,Angularfire,我试着把一张新唱片推到我的火炉上。但每次我收到这样的控制台错误: $scope.contacts.$add is not a function 这是我的密码: app.controller('contactsCtrl',['$scope','$firebaseObject',function($scope,$firebaseObject){ var ref = new Firebase("https://<database_details>.firebaseio.com/con

我试着把一张新唱片推到我的火炉上。但每次我收到这样的控制台错误:

$scope.contacts.$add is not a function
这是我的密码:

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);


    });

        }; 
  }]);
app.controller('contactsCtrl',['$scope','$firebaseObject',函数($scope,$firebaseObject){
var ref=新的火基(“https://.firebaseio.com/contacts");
$scope.contacts=$firebaseObject(参考)
$scope.addContact=函数(){
$scope.contacts.$add({
名称:$scope.name,
地址:$scope.address,
电话:$scope.telephone,
公司:$scope.company,
电子邮件:$scope.email
}).then(功能(参考){
var id=ref.key();
console.log('添加Id的联系人:'+Id);
});
}; 
}]);

您应该使用
$firebaseArray
而不是
$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);
    });
   }; 
  }]);
app.controller('contactsCtrl','$scope','$firebaseArray',函数($scope,$firebaseArray){
var ref=新的火基(“https://.firebaseio.com/contacts");
$scope.contacts=$firebaseArray(参考)
$scope.addContact=函数(){
$scope.contacts.$add({
名称:$scope.name,
地址:$scope.address,
电话:$scope.telephone,
公司:$scope.company,
电子邮件:$scope.email
}).then(功能(参考){
var id=ref.key();
console.log('添加Id的联系人:'+Id);
});
}; 
}]);