website/src/app/app.component.ts

28 lines
788 B
TypeScript
Raw Normal View History

2018-06-24 21:11:31 -04:00
import { Component } from '@angular/core';
2018-06-25 00:50:47 -04:00
import { AngularFirestore } from 'angularfire2/firestore';
import {share} from 'rxjs/operators';
2018-06-24 21:11:31 -04:00
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
2018-06-25 00:50:47 -04:00
formulas;
formula;
components;
unit = 'g';
newTotal: number = 0;
constructor(private db: AngularFirestore) {
this.formulas = this.db.collection('formulas').valueChanges();
}
displayFormula(formula) {
formula.components.map(row => row.component = this.db.doc(`components/${row.component.id}`).valueChanges().pipe(share()));
formula.total = formula.components.reduce((acc, row) => acc += row.quantity, 0);
this.newTotal = formula.total;
this.formula = formula;
}
2018-06-24 21:11:31 -04:00
}