0

I'm creating a window like component in Angular. On the top right of the component it can have set of buttons that do different things (like opening a modal, deleting something etc). See the image below for reference:

enter image description here

Now, we're using this type of layout in a lot of places within the application but with different set of buttons for the top right section. Now, in react doing this is pretty straightforward, I can simply pass any number of instanciated components as props to this component and display them.

What is the ideal way to do something like this in Angular?

1 Answer 1

1

A solution to this could be to pass the buttons into a display component. you can pass the buttons in using Content projection.

ng-content is a good example of this but could require you to have the buttons in the layout, for each view you are on, in order to pass them in.

Another solution would be to have all the buttons already exist inside the component and then only display the ones you need based on a input parameter.

You can also look into dynamic components which should allow you to switch out the components when needed.

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

2 Comments

Thanks, I was also looking into content projection. I'm already using ng-content to display some html/angular template code inside the window area.
Generally for the use cases I have experienced, that method is the simplest. Reusability of each button also plays a part.

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.