Ionic-Destroyed $firebaseArray object


#1

I am currently creating an Ionic 1 app and part of the app is i want to upload images to Firebase. I am currently following this Tutorial

Everything in the tutorial work until the last bit the adding to Firebase. The error I am getting is “Cannot call $add method on a destroyed $firebaseArray object”

This is the code I’m using which is within a controller:

function ($scope,$state ,$stateParams, $firebaseArray, $cordovaCamera) {

$scope.images = [];

var user = firebase.auth().currentUser;
if(user) {
var userReference = fb.child(“users/” + user.uid);
var syncArray = $firebaseArray(userReference.child(“images”));

$scope.images = syncArray;

} else {
console.log("")
$state.go(“login”);
}

$scope.upload = function() {
var options = {
quality : 75,
destinationType : Camera.DestinationType.DATA_URL,
sourceType : Camera.PictureSourceType.CAMERA,
allowEdit : true,
encodingType: Camera.EncodingType.JPEG,
popoverOptions: CameraPopoverOptions,
targetWidth: 500,
targetHeight: 500,
saveToPhotoAlbum: false
};
$cordovaCamera.getPicture(options).then(function(imageData) {
syncArray.$add({image: imageData}).then(function() {
alert(“Image has been uploaded”);
});
}, function(error) {
console.error(error);
});
}