0

I am implementing a simple grid component in angularjs. I prefer html configuration over javascript because that way view code and logic code is separated.

For example,

<my-grid> 
     <my-column title="Name" field"name"></column>
     <my-column title="Age" field"age"></column>
 </my-grid>

I have created a my-column component that requires a my-grid component. When the controller is initialized it inspects the element and calls addColumn function of my-grid.

I need to properly initialize all my-column before finally building the grid. Is there any hook after all nested controllers are initialized ($onInit function is called) ?

If not should I change my design what is the angularjs appropriate design ?

1
  • Do you now about the number of my-column components in my-grid? If yes, you could probably hide the grid initially, as long as all columns called $onInit and perform some kind of notification to the parent component. Commented May 14, 2019 at 8:12

1 Answer 1

0

In the end, I used scipper's recommendation with a little tweak.

The my-grid is initially on Initializing state.

Each sub component (for example my-column) in each $onInit notifies my-grid of it's presence and my-grid increments a counter.

When a sub component is finished or fails notifies again my-grid with the result and the counter is decremented.

When this counter reaches zero, all sub components are initialized. This is checked both on $postLink and whenever a sub component is finishes. The $postLink is required in case there are no sub components at all.

While the grid is initializing, a nice loading bar is displayed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.