angularjs - AngularFire 0.8 bindTo only works for first change -


Hi, I am trying to create an app using the new Analyzer version 0.8, which has an updated version of the $ bind, which is $ bindTo Although IM is getting a little hard with this method, the only way to tie the changes seems to be back in the firebase on the first update. Do not make later changes to the data on the page. Do I need to redeem the object on every update?

I have created a simple app to show this problem. In the app, any object is created in a factory (test) that adds the object to the $ root scope. The administrator then accesses it, and a viewer accesses it and updates as needed.

Factory (services / test.js)

  app factory ('test', function ($ firebase, FIREBASE_URL, $ rootScope) { Var URL = FIREBASE_URL + 'test12 /'; var test = {create: function (user, obj) {console.log ("create new test object"); Obj.something = "1234"; obj.somethingElse = "567" ; Obj. $ Priority = "7"; obj. $ Save (set); setCurrentTest (user);}, meet current: function () {Return $ rootScope .currentTest;}}; Function Set Bootstrap (user) {var obj = $ Firebase (new firebase). $ AsObject (); obj. $ Loaded (). Then (function () {if (obj. $ Priority) {Obj. $ BindTo ($ rootScope, 'CurrentTest'). Then (function () {console.log ("bound");});} else {Test.create (user, obj);}});} $ RootScope. $ ('$ FirebaseSimpleLogin: Login ', function (e, user) {setCurrentTest (user);}); return exam;});  

Controller (administrator / test.js)

  app.controller ('TestCtrl', function ($ scope, test) )) {$ Scope.testy = Test.getCurrent ();});  

See (test.html)

  & lt; Div class = "t_center" & gt; & Lt; H3 & gt; Trial & lt; / H3 & gt; & Lt; Div & gt; & Lt; Input type = "test" name = "test1" value = "testy.something" ng-model = "testy something." /> & Lt; Input type = "test" name = "test2" ng-model = "testy.somethingElse" /> & Lt; / Div & gt; & Lt; Br / & gt; & Lt; / Div & gt;  

is using IM;

  • Angular # 1.2.21
  • Firebase # 1.0.18
  • Firebase - Simple-Login # 1.6.2

Any advice was greatly appreciated.

Background I do not think my example code highlights that I was trying to get very well, so for everything I was trying to do I will provide a little background The object I create here (for example, called "test") is basically a user profile. There are some preferences in the types of common use (name etc.), instead of copying the code that is used by all controllers, I wanted to create that service, which had obtained a user profile on login and it The $ root that was placed in was necessary for some controllers. If a profile is not available in the service system, then it makes it (with the sensible value).

Because it looks like a mess of $ root scope, so it was not easy to understand that your example What's wrong in With a service and $ bindTo

  var app = angular Modules ("Sample Application", ["Firebase"]); App.constant ('FIREBASE_URL', 'https://kato-so25069621.firebaseio-demo.com/'); App.factory ('test', function ($ firebase, FIREBASE_URL) {return function (path) {var URL = FIREBASE_URL + path; var obj = $ firebase (new firebase). $ AsObject (); obj. $ Weighted (function () {console.log ('loaded', obj); if (obj. $ Value === null) {// if the object is not started angular. Extend (obj, {something: "1234 ", Some examples:" 567 ", $ priority: 7}); obj. Save ();}}); return obj;}}); App.controller ('TestCtrl', function ($ scope, test) {test ('test12 /').$ bindTo ($ scope,' testy ');});  

Note these important principles:

  • The service is no longer limited to $ root scope
  • We currently use $ bindTo $ Scope, so when it is destroyed it automatically closes
  • We do not worry about authentication within our service but assume that the user is already certified, below See more

The only component here is the missing authentication, which is deliberately missing out E was. It should not be checked in every service and controller (instead, use simple login with router in the guide below.


Comments