我試圖做一個簡單的CRUD與離子(v1)和angularfire。我可以閱讀和刪除記錄,但我需要編輯和創建。實際的問題是angularfire函數$ add`,這個函數不會執行任何操作,並且不會在控制檯中返回任何錯誤。我有這樣的代碼:
$scope.users = $firebaseArray(root.ref('/users/'));
$scope.user = {};
//Create
$scope.title = "New user"
$scope.button = "Create";
$scope.icon = "ion-person-add";
$scope.submit = function() {
var data = {
name: $scope.user.name,
username: $scope.user.username,
email: $scope.user.email,
street: $scope.user.street,
suite: $scope.user.suite,
city: $scope.user.city,
lat: $scope.user.lat,
lng: $scope.user.lng,
phone: $scope.user.phone,
website: $scope.user.website,
}
console.log(data);
$scope.users.$add(data).then(function (ref) {
console.log('contact added with Id: ' + id);;
})
顯然,代碼是好的,但不返回console.log
所以也許有一些錯誤。有任何想法嗎?
錯誤是「錯誤:密鑰ID未定義,無法在JSON中傳遞未定義,請改爲使用null」。 –