Skip to content

Commit

Permalink
Tentando entender como funcionam as listas 'angular/angularfire#1158'
Browse files Browse the repository at this point in the history
  • Loading branch information
Emanuel Victor de Oliveira Fonseca committed Jan 12, 2018
1 parent 6740145 commit 65b08f1
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@

<div *ngFor="let atendente of atendentes" routerLink="{{atendente.key}}">
<mat-list-item>
<h3 matLine> {{atendente.nome}} </h3>
<h4 matLine> {{atendente.email}} </h4>
<p matLine *ngIf="atendente?.endereco?.key"> {{atendente?.endereco?.cidade?.nome}} -
{{atendente?.endereco?.cidade?.estado?.uf}} </p>
<h3 matLine> {{atendente?.payload?.val()?.nome}} </h3>
<h4 matLine> {{atendente?.payload?.val()?.email}} </h4>
<p matLine *ngIf="atendente?.payload?.val()?.unidade?.endereco"> {{atendente?.payload?.val()?.unidade?.endereco}}</p>
</mat-list-item>
<mat-divider></mat-divider>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class ConsultarAtendentesComponent implements OnInit {
/**
*
*/
public atendentes: Atendente[];
public atendentes: any;

/**
*
Expand All @@ -37,7 +37,14 @@ export class ConsultarAtendentesComponent implements OnInit {
*
*/
public listUsuariosByFilters() {
this.atendenteService.find().subscribe(atendentes => this.atendentes = atendentes)
this.atendenteService.find().snapshotChanges().subscribe(atendentes => {
this.atendentes = atendentes;
this.atendentes.forEach( atendente => {
console.log('aqui');
atendente.payload.val().unidade.endereco = 'asdfas';
// atendente.payload.val
})
})
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<!--card informações-->
<mat-card-content>

<visualizar-dados-usuario [usuario]="atendente" *ngIf="atendente?.key" flex>
<visualizar-dados-usuario [usuario]="atendente?.payload?.val()" *ngIf="atendente?.key" flex>
<!--options-->

<div layout="column" layout-align="start end" flex>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class VisualizarAtendenteComponent implements OnInit {
*
* @type {Atendente}
*/
atendente: Atendente = new Atendente();
atendente: any;

/**
*
Expand All @@ -47,7 +47,7 @@ export class VisualizarAtendenteComponent implements OnInit {
* @param {string} atendenteKey
*/
public find(atendenteKey: string) {
this.atendenteService.findOne(atendenteKey).subscribe(atendente => this.atendente = atendente)
this.atendenteService.findOne(atendenteKey).snapshotChanges().subscribe(atendente => this.atendente = atendente)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ export class ConsultarUnidadesComponent implements OnInit {
*
*/
public listUnidadesByFilters() {
this.unidadeService.find().snapshotChanges().subscribe(asdf=> {
this.unidades = asdf;
this.unidadeService.find().snapshotChanges().subscribe(result => {
this.unidades = result;
});
}

Expand Down
15 changes: 5 additions & 10 deletions src/web/domain/service/atendente.service.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
import {Injectable} from '@angular/core';
import {HttpClient} from "@angular/common/http";
import {AbstractService} from "./abstract.service";
import {AngularFireDatabase} from "angularfire2/database";
import {AngularFireDatabase, AngularFireList, AngularFireObject} from "angularfire2/database";
import {Observable} from "rxjs/Observable";
import {Atendente} from "../entity/atendente/atendente.model";

@Injectable()
export class AtendenteService extends AbstractService {

/**
* TODO mudar para o model
*/
atendentes: any[];

constructor(private af: AngularFireDatabase, private httpClient: HttpClient) {
super();
}
Expand All @@ -21,12 +16,12 @@ export class AtendenteService extends AbstractService {
return this.httpClient.post(this.baseUrl + 'atendentes', atendente).toPromise();
}

public find(): Observable<any[]> {
return this.af.list<any[]>('atendentes').valueChanges();
public find(): AngularFireList<any[]> {
return this.af.list<any[]>('atendentes');
}

public findOne(key: string): Observable<any> {
return this.af.object<any>('atendentes/' + key).valueChanges();
public findOne(key: string): AngularFireObject<any> {
return this.af.object<any>('atendentes/' + key);
}

public update(atendente: Atendente): Promise<any> {
Expand Down
7 changes: 0 additions & 7 deletions src/web/domain/service/unidade.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ import {FirebaseListObservable} from "angularfire2/database-deprecated";
@Injectable()
export class UnidadeService extends AbstractService {

/**
* TODO mudar para o model
*/
unidades: any[];

constructor(private af: AngularFireDatabase, private httpClient: HttpClient) {
super();
}
Expand All @@ -24,8 +19,6 @@ export class UnidadeService extends AbstractService {
}

public find(): AngularFireList<any> {

// this.unidadeService.find().snapshotChanges().subscribe(
return this.af.list('unidades');
}

Expand Down

0 comments on commit 65b08f1

Please sign in to comment.