A
A
Abra Kadabra2018-05-23 15:15:15
Angular
Abra Kadabra, 2018-05-23 15:15:15

How to make a component wait for data to load?

There is a component (a graph that is drawn according to the given data), the data for drawing is transmitted using @Input. The component draws the SVG path when it is initialized (the usual chart() method is called).

ngOnInit(){
  this.chart();
}

Everything is fine if you do not have to wait for data to load.
How can the component make sure the data is in place?
Is it generally the task of the component, or the parent?
I can't just call the el.chart() function from the parent component, can I?
*Charts per page - 6

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
theykillimmortal, 2018-05-23
@Jmaster

Hello. If I understood your problem correctly, then you'd better look towards OnChanges . This way you can also redraw charts if the incoming data has changed.
As a tip, don't forget to make a destroy() method for your charts and call it in OnDestroy .

D
Dmitry Eremin, 2018-05-23
@EreminD

the code would be
both the parent and the current component

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question