关注Lynda.com使用Angularjs构建数据驱动的应用程序。 我正在使用MeetingsController尝试将数据推送到Firebase,并且我收到以下错误:
TypeError: undefined is not a function
at g.$scope.addMeeting (meetings.js:10)
这指向 meetings.push 行
MeetingsController
myApp.controller('MeetingsController', function($scope, $firebaseObject) {
var ref = new Firebase('https://attendanced****.firebaseio.com/meetings');
var meetings = $firebaseObject(ref);
$scope.meetings = meetings;
$scope.addMeeting = function() {
meetings.push({
name: $scope.meetingname,
date: Firebase.ServerValue.TIMESTAMP
}).then(function() {
$scope.meetingname='';
});
}; //addmeeting
});
由于Firebase删除$ firebase并用$ firebaseObject替换$ asObject(),我已经从给定代码的路线更改了控制器。 我看到Firebase现在使用的是.push()而不是。$ push()。 我确实看到问题29053103触及了类似的问题,但结束时原始海报不得不恢复到旧版本的AngularFire和Firebase,以使其工作,我宁愿不这样做。
答案 0 :(得分:1)
您可以将对象推送到数组,但不能将对象推送到对象。
我希望能修好您的应用:
...
//I assume that meetings is more then one so that should be $firebaseArray instead of $firebaseObject
$scope.meetings = $firebaseArray(ref);
$scope.addMeeting = function() {
//you can use $add instad of push that will save yoour object to firebase
meetings.$add({
name: $scope.meetingname,
date: Firebase.ServerValue.TIMESTAMP
}).then(function() {
$scope.meetingname='';
});
...
}; //addmeeting