Pipe in Angular returns the values in the console but not in the screen

1

I have this pipe , it prints me in the console the values I want but not on the screen.

This is the pipe code:

import { Injectable, Pipe } from '@angular/core';

// AngularFire
import { AngularFire } from 'angularfire2';

// Firebase
import firebase from 'firebase';

@Pipe({
  name: 'sumacategorias'
})
@Injectable()
export class Sumacategorias {

    public lasuma;
    public existeArticulo;

    constructor(public af:AngularFire){}

    transform(value, args?) {

        // Referencia para cargar los valores totales de las compras en el mes corriente
        let comprasTotales = firebase.database().ref('artxcategoria/' + value);

        // Verificamos si existe la tabla
        this.existeArticulo = this.af.database.list('artxcategoria/' + value);

        this.existeArticulo.subscribe( x => {
            if(!x.length){
              console.log('No hay tabla aún.');
            }else{
              // Cargamos los datos
              comprasTotales.on('value',valor =>{

              let contenedor = [];
              let valores = valor.val();
              let keys = Object.keys(valores);

              //  Guardamos los valores para sumarlos
              for(let i of keys){
                var total = valores[i].cantidad;
                contenedor.push({total}); 
              }
              // Operación Sumar
              var sum = 0;

              contenedor.forEach(function(val){
                      sum = sum + val.total;
                });
              this.lasuma = sum;
        });
      }
      console.log('Valores: ' + this.lasuma);
      return this.lasuma;
    });
  }
}
    
asked by Luis Miguel 11.03.2017 в 01:08
source

0 answers