#Issue with checking for update observer

14 messages · Page 1 of 1 (latest)

west geyser
#

Im trying to dynamically render components with data, Upon selecting, the person is added to a observable. The rendering component is subscribed to the observable and when he observes a person being added to the obeservable, he should use the data that comes in to fill up the rendered components

#

Right now the situation is - i add person to the dashboard, but nothing happens. When i swap routes and return to the page, the info loads just fine

west geyser
#

i looked at the lifecycle methods but i dont think there is really a way to do what i am trying to do

west geyser
#

Maybe it is a routing issues, if i manually route to the page it works fine

gilded cradle
#

You subscribe to this.consultantService.data$, but you don't do anything with the received data. You need to set the input to the component every time it changes.

west geyser
gilded cradle
#

That is done once, when you create the component. But the data is emitted several times after that, so every time it changes, the input must be set again. It seems you're a newbie. Why are you creating components dynamically that way? Why don't you use the template and let Angular create components for you?

west geyser
#

"But the data is emitted several times after that, so every time it changes, the input must be set again." what do you mean? i use a eventEmitter to add a person to a observable, will this be done multiple times?

#

and im creating a dashboard with "widgets" template components which can be added through a add Widget component

#

and yeh i would still call myself a newbie 😄

gilded cradle
#

An observable is used to represent a flow a values being emitted over time, usually asynchronously. Every time you call setConsultant() on your service, the observable emits a new data.
Since this data is supposed to be passed as input to your components, you need to do it.

west geyser
#

so from the subscribe function i would need to clear the references and rerender with the new inputs?

gilded cradle
#

No. You would need to call setInput() on your components.

west geyser
#

ah i see