Firebase and Angular2

0

Alright?

I do not know what's missing to get the Firebase response using Angular2. I followed a tutorial that worked, but when trying on my project, I get 'null'. I do not know if I use FirebaseObjectObservable or FirebaseListObservable. Well, let's go to the code.

import { Component } from '@angular/core';
import { AngularFire, FirebaseObjectObservable  } from 'angularfire2';

@Component({
  selector: 'app-marcas',
  templateUrl: './marcas.component.html'
})

export class MarcasComponent {
    meufirebase: FirebaseObjectObservable<any[]>;
    constructor(af: AngularFire) {
    this.meufirebase = af.database.object('/marcas/marca_1/nome');
  }
}

And my html:

<label>Escolha a marca</label>
<select materialize="material_select" [materializeSelectOptions]="marcas" class="browser-default">
  <option  *ngFor="let marca of marcas">{{ marcas.nome }}</option>
</select>

And an image of how I set up my Firebase

I'mwaitingforalittleguru'shand!Ahug!

Ihaveeditedapartofthecomponentcodeto:

constructor(af:AngularFire){constqueryObservable=af.database.list('/marcas',{query:{orderByChild:'nome'}});//subscribetochangesqueryObservable.subscribe(queriedItems=>{console.log(queriedItems);});}}

AndnowontheconsoleIhave:

In other words, I'm getting to Firebase, but something is still missing, since I do not understand those Object that should be tag_1, tag_2, tag_3 and tag_4 according to the structure of my bank ...

    
asked by anonymous 26.11.2016 / 23:33

1 answer

1

My firebase collection

Mycomponent

import{Component}from'@angular/core';import{AngularFire,FirebaseListObservable}from'angularfire2';@Component({selector:'app-root',templateUrl:'./app.component.html',styleUrls:['./app.component.css']})exportclassAppComponent{title='appworks!';marcas:FirebaseListObservable<any[]>;constructor(privateaf:AngularFire){this.marcas=af.database.list('/Marcas');console.log(this.marcas);}}

MyView

<h1>{{title}}</h1><hr><ul><li*ngFor="let marca of marcas | async">
    {{marca.$key}} {{ marca.name}}
  </li>
</ul>

    
27.11.2016 / 13:47