Comments (7)
You should probably be doing this by simply destroying the scope on which
you have created the binding.
On 12 April 2013 17:30, Alexandre Bourget [email protected] wrote:
I bind a "$scope.data" to angularFire, using the normal method, inside a
Controller.From that point on, any change to data will get reflected to a certain
location in Firebase.At some point, I have a select box to switch profile, so I replace datawith a "new" profile. I would like to be able to unwatch the previous one,
because I'm now changing the location
of the data in Firebase (to a different profile, thus a different URL).Right now, if I call angularFire() again, with $scope and data, it'll add
a second set of watches, and write to BOTH locations.. which becomes
increasingly odd :)Also, right now if I try to remove or replace my data element, it deletes
on the Firebase side.. which isn't very nice once I'm done editing.To attempt to fix this, I added a way to remove watches by tweaking the
call to $watch this way:var unwatch = $scope.$watch(name, function() {
if (self._initial) {
self._initial = false;
return;
}
var val = JSON.parse(angular.toJson($scope[name]));
if (angular.equals(val, self._remoteValue)) {
return;
}
self.fRef.set(val);
}, true);
$scope['$ngFireUnwatch' + name] = unwatch;First and last lines are important here.
So I manage to be able to remove the watches from my code, before calling
angularFire again.. and it works the first or second time I switch.. but
then it completely deletes my objects from Firebase.How could we solve this elegantly ?
thanks for your great work
—
Reply to this email directly or view it on GitHubhttps://github.com//issues/13
.
from angularfire.
But I get another kind of problem.. it's that the fRef inside the angularFire keeps those fRef.on('value') bound.. and that's what's causing problems afterwards..
It seems that Firebase is kind of keeping a cache of those URLs we're passing through.. so keeps the hooks up if you come back and call angularFire() another time with the same URL..
So I kind of fixed it with:
$scope['$ngFireUnwatch_' + name] = function() {
self._fRef.off('value');
unwatch();
}
otherwise, it was deleting my things.
I thought of using the $scope.. but then my controller,s scope has other uses.. and I can't clean it up just to trigger one mechanism. And also.. I think the problem would persist, because it goes inside Firebase.. and its caching system (didn't look there though).
from angularfire.
AngularFire should be listening to the $destroy event on the scope to which
it is associated to do the unbinding.
If you are needing to bind and unbind values then I would, personally be
creating a new scope for this. This is what inherited scopes are for.
Just have another controller within the controller that you are currently
using.
Pete
On 12 April 2013 18:11, Alexandre Bourget [email protected] wrote:
But I get another kind of problem.. it's that the fRef inside the
angularFire keeps those fRef.on('value') bound.. and that's what's causing
problems afterwards..It seems that Firebase is kind of keeping a cache of those URLs we're
passing through.. so keeps the hooks up if you come back and call
angularFire() another time with the same URL..So I kind of fixed it with:
$scope['$ngFireUnwatch_' + name] = function() {
self._fRef.off('value');
unwatch();
}otherwise, it was deleting my things.
I thought of using the $scope.. but then my controller,s scope has other
uses.. and I can't clean it up just to trigger one mechanism. And also.. I
think the problem would persist, because it goes inside Firebase.. and its
caching system (didn't look there though).—
Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-16305054
.
from angularfire.
Hmm.. yeah.. and angularFire isn't even listening to $destroy as I can see.. and upon $destroy-ction, if should _fRef.off('value') to make sure it's detached from Firebase too.
Anyway.. I've got something semi-working here.. I'll probably push to my branch if I'm satisfied a bit later. Maybe this will need more reflection.
from angularfire.
We should certainly be adding handling $destroy.
On 12 April 2013 18:33, Alexandre Bourget [email protected] wrote:
Hmm.. yeah.. and angularFire isn't even listening to $destroy as I can
see.. and upon $destroy-ction, if should _fRef.off('value') to make sure
it's detached from Firebase too.Anyway.. I've got something semi-working here.. I'll probably push to my
branch if I'm satisfied a bit later. Maybe this will need more reflection.—
Reply to this email directly or view it on GitHubhttps://github.com//issues/13#issuecomment-16306275
.
from angularfire.
Good catch @abourget - as @petebacondarwin suggests handling $destory would be a great start.
from angularfire.
FWIW, you can also use the disassociate callback provided to the promise on resolution (added via pull request #34).
from angularfire.
Related Issues (20)
- Error: Metadata version mismatch for module node_modules/angularfire2/index.d.ts, found version 4, HOT 2
- JS console error displaying my API Key on failed login - Chrome only
- Your library does not support callbacks for set(), push(), while Firebase does
- Are there any plans to include ML Kit support?
- ng build --prod || Can't resolve './public_api' in '/node_modules/angularfire2/database' HOT 1
- firestorage $putString callbacks not binding HOT 2
- Firestore support HOT 1
- Dependency Update HOT 1
- I keep getting "TypeError: Right-hand side of 'instanceof' is not callable" error no matter what sign in method I try
- Firestore is loading all data in every new insert or any updates
- callable functions throw deadline-exceeded even though the function was defined with max timeout in nodes HOT 2
- New Console Error "TypeError: v12 is not a function" With Version 0.9.2 HOT 1
- 'child_added' does not trigger when re-adding same item to RTDB
- 'child_removed' triggers on setting listener, before child is removed
- ERROR Error: Uncaught (in promise): TypeError: Cannot convert undefined or null to object HOT 1
- ERROR TypeError: ZS(...).firestore is not a function HOT 1
- Email verification HOT 1
- Uncaught TypeError: Cannot read property 'GoogleAuthProvider HOT 1
- auth.signInAnonymously() support HOT 1
- Potential Security Issue
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from angularfire.