Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 49252

Firebase Dynamic Querying using results of barcode scanner (Ionic 3 & Angularfire2)

$
0
0

@ielkadi wrote:

#I’m fairly new to Ionic 3, so please bare with me. I have a case where I need to dynamically retrieve the results of a specific book. I would like to retrieve that specific book by using its ISBN number (highlighted in bold below). This is how my database looks like:

firebase_results

Before I dive into the code, here is some important information I think you need to know. What I am trying to specifically do is use a barcode scanner to scan the ISBN number of a book. Then I would like to use that scanned ISBN number to dynamically retrieve results from that database. With that being said, I need to design my code in such a way that the barcode scanner variable is updated every single time (with each scan) to the new barcode number (already completed). Then that barcode number is fed into the query (which I still can’t get to work, and is what I need help with) which retrieves a child node based on that number.

My code:
import { Component } from ‘@angular/core’;
import { IonicPage, NavController, NavParams, AlertController } from ‘ionic-angular’;
import { BarcodeScanner, BarcodeScannerOptions } from ‘@ionic-native/barcode-scanner’;
import { AngularFireAuth } from ‘angularfire2/auth’;
import { AngularFireDatabase, AngularFireList } from ‘angularfire2/database’;
import { HomePage } from ‘…/home/home’;
import { Observable } from ‘rxjs/Observable’;

@IonicPage()
@Component({
selector: ‘page-login’,
templateUrl: ‘login.html’,
})
export class LoginPage {

bookResults: Observable<any[]>;
nightly_build: AngularFireList<any[]>;
options: BarcodeScannerOptions;
results: {};
constructor(public navCtrl: NavController,
public navParams: NavParams,
private fire: AngularFireAuth,
private database: AngularFireDatabase,
private barcodeScanner: BarcodeScanner,
private alertCtrl: AlertController) {

    this.bookResults = this.database.list('results').valueChanges();
    this.nightly_build = this.database.list('night_build');

}

async Scan(){
this.results = await this.barcodeScanner.scan();
this.results = this.results[‘text’];
}

Logout(){
this.fire.auth.signOut();
this.navCtrl.setRoot(HomePage);
}
}

Right now, what happens is that the “this.bookResults = this.database.list(‘results’).valueChanges();” retrieves the above database. However, I need some guidance as to how to change my query such that I can retrieve specific child nodes based on the “isbnNumber” instance of each child.

I’ve tried several things. More recently I’ve tried:

this.bookResults = this.database.list(’/results’,{
query: {
orderByChilde: isbnNumber,
equalTo: this.results,
}
});

but that didn’t work. I’ve tried other things such as:
this.bookResults = this.database.list(’/results/${this.results}’).valueChanges();

but it hasn’t worked either.

I’ve read various stackoverflow, github, and ionict threads, so I wouldn’t be surprised if this was marked as duplicate. I have tried following the instructions of various threads, yet I felt that the way retrieving information from the database didn’t specifically apply to my current situation, as the values used to retrieve specific child nodes where hardcoded into the query. I need a dynamically changing query that adjusts itself based on the barcode scanner’s results).

Please let me know if there is anything that was unclear from this post, and I’d be more than happy to help. Also, if you are interested in seeing the source code, here is a link to my github repo containing it:

https://github.com/islamaymansais/honey_scanner (go to src -> pages -> login -> login.ts)

Thanks for taking the time to read this long post. I am a beginner , I’ve gone through plenty of posts but unfortunately I was not able to apply the appropriate changes due to my lack of experience with ionic.

Please advice.

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 49252

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>