I have a very simple component that makes a nice little dashboard card and I can reuse it for multiple pieces of data. When I use test data, my condition works great, as it sends the data immediately and picks the correct pipe. However, on the real dashboard it calls for the data from an API. The data is returned but since this is no longer in the ngOnInit, my condition doesn't fire. Would anyone know how I might pick the right condition after getting data back from my service?
Component:
import { Component, OnInit } from '@angular/core';
import {SecondsToMinutesPipe} from "../seconds-to-minutes.pipe";
import { DecimalPipe } from "@angular/common";
@Component({
selector: 'app-dash-stat',
inputs: [
'icon', 'color', 'amount', 'description', 'time'
],
templateUrl: './dash-stat.component.html',
styleUrls: ['./dash-stat.component.css'],
})
export class DashStatComponent implements OnInit {
private loading: boolean = true;
private icon: string;
private color: string = '#fff';
private amount: any = 0;
private description: string;
private time: boolean = false;
constructor(private timePipe: SecondsToMinutesPipe, private numberPipe: DecimalPipe) { }
ngOnInit() {
this.loading = false; //remove this and figure out
if(this.time){
this.amount = this.timePipe.transform(this.amount);
}
else
{
this.amount = this.numberPipe.transform(this.amount, '1.0-0');
}
}
}
And I call it from my dashboard like this:
<div class="col-sm">
<app-dash-stat icon="fa-tint" color="#eb1c2d" description="Litres Flown" amount="{{dashStats.volume}}"></app-dash-stat>
</div>
<div class="col-sm">
<app-dash-stat icon="fa-clock-o" color="#fd6b00" description="Average Loading Time" amount="{{dashStats.filltime}}" time="true"></app-dash-stat>
</div>