angularjs - Can't $update or $set ~ "undefined is not a function" ~ AngularFire -
what i'm trying do: update status "taken" when chat closed.
issue: can't $scope.currentchat.$set()
or $scope.currentchat.$update()
work when trying update status. (see $scope.close()
function.)
what i've tried: various methods including $set, $update; don't know. lot of things. been researching several hours, , can't find solution works.
notes:
$scope.currentchat.$set({status:"taken"});
doesn't work. $scope.currentchat.$getrecord('status');
works. returns:
object {$value: "open", $id: "status", $priority: null}
so going on here? why can't seem set status taken?
the issue in $scope.close() function, when trying update status:
// $scope.close // - closes current ticket. $scope.close = function() { // $scope.ticketobject.status = "taken"; // $scope.currentchat.$set({status:"taken"}); console.log("==========================="); console.log("status:"); console.log($scope.currentchat.$getrecord('status')); console.log($scope.currentchat['status']); console.log("==========================="); $scope.ticketobject = {}; $scope.ticket = false; $scope.toggle(); }
here's code:
bloop.controller('homectrl', ['$scope', '$firebase', function($scope, $firebase) { console.log("homecontroller!"); var url = 'https://**********.firebaseio.com/tickets/'; var ref = new firebase(url); // $scope.createticket // - function makes connection firebase , creates ticket. $scope.createticket = function() { $scope.tickets = $firebase(ref).$asarray(); $scope.tickets.$add($scope.ticketobject).then(function(r) { var id = r.name(); $scope.currentfbid = id; $scope.synctickets(); console.log("==========================="); console.log("created ticket: " + $scope.currentfbid); console.log("url: " + url + $scope.currentfbid); console.log("==========================="); }); } // $scope.synctickets // - function makes connection firebase , syncs ticket $scope update tickets. $scope.synctickets = function() { var ticketrefurl = new firebase(url + $scope.currentfbid); $scope.currentchat = $firebase(ticketrefurl).$asarray(); $scope.currentchat.$save($scope.ticketobject); var archiverefurl = new firebase(url + $scope.currentfbid + "/archive"); $scope.currentchat.archive = $firebase(archiverefurl).$asarray(); console.log("==========================="); console.log("saved ticket: " + $scope.currentfbid); console.log("url: " + ticketrefurl); console.log("archive url: " + archiverefurl); console.log("==========================="); } // $scope.post // - function pushes whatever typed chat chat archive. // - $scope.ticketobject.archive (is array of objects) $scope.post = function(name) { // push ticketobject.archive array... $scope.ticketobject.archive.push({ "name" : name, "text" : $scope.chattext }); // logging array make sure exists... console.log("==========================="); console.log("chat archive:"); console.log($scope.ticketobject.archive); console.log("==========================="); $scope.currentchat.archive.$add({ "name" : name, "text" : $scope.chattext }); // resets text area it's empty... $scope.chattext = ""; } // works // $scope.close // - closes current ticket. $scope.close = function() { // $scope.ticketobject.status = "taken"; // $scope.currentchat.$set({status:"taken"}); console.log("==========================="); console.log("status:"); console.log($scope.currentchat.$getrecord('status')); console.log($scope.currentchat['status']); console.log("==========================="); $scope.ticketobject = {}; $scope.ticket = false; $scope.toggle(); } // $scope.toggle // - function toggles chat either open or closed. $scope.toggle = function() { if($scope.togglestate === false) { $scope.togglestate = true; $scope.checkticket(); } else if($scope.togglestate === true) { $scope.togglestate = false; } } // $scope.checkticket // - function checks see if there's existing ticket. // - if there's not existing ticket, creates one. $scope.checkticket = function() { if($scope.ticket === false) { // generate new ticket data $scope.ticketobject = newticket(); // create ticket $scope.createticket(); // ticket exists. $scope.ticket = true; } } function newticket() { var ticketid = generateticketid(); var newticket = { id: ticketid, status: "open", name: "n/a", email: "n/a", date: generatedate(), opid: "unassigned", opname: "unassigned", archive: [], notes: [] } return newticket; } function generateticketid() { var chars = "0123456789abcdefghjklmnpqrstuvwxyz"; var result = ''; for(var i=12; i>0; --i) { result += chars[math.round(math.random() * (chars.length - 1))]; } return result; } function generatedate() { var today = new date(); var dd = today.getdate(); var mm = today.getmonth() + 1; var yyyy = today.getfullyear(); if(dd < 10) { dd = '0' + dd; } if(mm < 10) { dd = '0' + mm; } var date = mm + "/" + dd + "/" + yyyy; return date; } }]);
$update , $set part of $firebase api. attempting call them on synchronized array returned $asarray()
, $firebasearray
instance. has its own api, includes neither update nor set.
Comments
Post a Comment