Q
Q
qqqqqqqqqqqa2021-12-13 23:22:26
Angular
qqqqqqqqqqqa, 2021-12-13 23:22:26

How to use the components created by Angluar in other creations. components, BREAKING the hierarchy?

Below is part of the Angular project tree:

61b7ad2f64805156408832.png
The project already has 2 artificially created modules (components) - n1 and n2 , and the original app component .
The joke is that the main feature of Angular and similar frameworks, as I understand it, is modularity and the fundamental ability to create your own super-duper components, but for some reason in Anular you can’t just use the created components anywhere. Those. By default, in this project, I can use n1 and n2 for / when creating an app component, but they can no longer be used in index.html itself. And not only in idex.html, as well as in some other elements, this will not work, as I understand it, due to non-export and non-import of component classes to certain components.
How can components import classes of other components for their further use when creating new components, and is there an automated script / option in ng cmd for this , so as not to run and export everything everywhere (something like the already existing ng g component "name")?
I'm new

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vitaly Kadyrov, 2022-01-09
@Ahmad66617

Perhaps the question about exporting classes is not quite correctly asked - but in such a case I usually use a common or shared folder and a shared module with components that will be used in other modules and / or jointly, if it means reusing some part of it inside the component - then this also put the part into a separate component (for example, some kind of input or checkbox) - and assemble the constructor as needed. This is the advantage of angular - modularity and encapsulation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question