Firebase + Angularjs + Python

Ok, I use the angularFire-seed repository to check how I will connect the angularjs + firebase + python-firebase library.

My goal is to add material to firebase from python scripts and show it on a web page.

this is the controller:

...... angular.module('myApp.controllers', []) .controller('MyCtrl1', ['$scope', 'FBURL', 'angularFire', function($scope, FBURL, angularFire) { angularFire(FBURL+'/syncedValue', $scope, 'syncedValue', ''); }]) ...... 

this is a view:

  ...... <h4>{{syncedValue}}</h4> <input ng-model="syncedValue" type="text" /> ...... 

Everything is working fine:

enter image description here


firebase debugger

It works! When I inject material into a web page, it appears in the firebase debugger.

Now I do this in python:

  from firebase import Firebase f = Firebase("https://xxxxx.firebaseio.com/syncedValue") r = f.update({"syncedValue": "3433"}) 

This makes the child element syncedValue:

firebase debugger

  r = f.push({"syncedValue": "3433"}) 

This makes the child with uid:

enter image description here

But I want to just simply update the value of the syncedValue key without adding any child, for example ...

Shed something in angularjs, I don't understand.

+4
source share
2 answers

I understood!

  from firebase import Firebase f = Firebase("https://xxxxx.firebaseio.com/syncedValue") r = f.update({"syncedValue": "3433"})**strong text** 

this code updates the syncedValue child so ....

I just made a child in the controller:

  ...... angular.module('myApp.controllers', []) .controller('MyCtrl1', ['$scope', 'FBURL', 'angularFire', function($scope, FBURL, angularFire) { angularFire(FBURL+'/syncedValue/1', $scope, 'syncedValue', ''); }]) ...... 

enter image description here

+3
source

There is a really simple library available in Python for working with Firebase with less complicated syntax. You should check this out: https://github.com/andela-cnnadi/pyfirebase .

In this case, you can do something like this

 from pyfirebase import Firebase f = Firebase('https://xxxxx.firebaseio.com/') ref = firebase.ref('syncedValue') ref.set(3433) 

Then you can continue updating this ref when you want to use the same syntax:

  ref.set("newValue") 
0
source

Source: https://habr.com/ru/post/1498786/


All Articles