Component Registration in Parent Class component

31 views
Skip to first unread message

Nay Soewin

unread,
Nov 23, 2020, 11:07:36 PM11/23/20
to Angular and AngularJS discussion
Hello all, 

I am new in angular and come from VueJS, i am a fuse confusing about registration components , 

Is it angular have only option that we can register all of created component in to app.module.ts as global with unique selector name 

any options i can register a couple of component in to specific component class like Vuejs.

Let say , I have DepartmentComponent class as parent then i just want to register this tow child DepartmentModal and DepartmentTable without declarations in app.modules.js

Thanks all

Arnaud Deman

unread,
Nov 24, 2020, 10:31:23 AM11/24/20
to Angular and AngularJS discussion
Hello,


You could have a DepartmentModule in which the DepartmentComponent, DepartmentModal and DepartmentTable are delcared. If DepartmentModal and DepartmentTable are only used in DepartmentComponent, they don't have to be exported in DepartmentModule, only DepartmentComponent has to be exported.

In app.module you will have to import DepartementModule if it is used in the app component. If it is used in another component you will have to import in its corresponding module and not in the app.module. Otherwise if it is associated to a route it can be - and should be - lazy loaded.

Regards,
Arnaud.

References:

Nay Soewin

unread,
Nov 24, 2020, 12:06:12 PM11/24/20
to ang...@googlegroups.com
Hello Arnaud,

Thank you so much for your reply and explanation in detail as well. Please let me clear one more thing to you
. Is it correct that all of a component's selector should be a unique name if we try to export from a module and use it in other components?

Best Regards,
Marty Collins

--
You received this message because you are subscribed to the Google Groups "Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/angular/52d1b77b-1ff0-430b-8754-42907452446dn%40googlegroups.com.

Arnaud Deman

unread,
Nov 24, 2020, 12:28:55 PM11/24/20
to Angular and AngularJS discussion
Hi Marty,
The selector is a css selector (or several css selectors) that will be used to determine the component to insert. Thus, if the same selector is associated with several components, it will not be possible to determine which component must be inserted. I suppose it is possible if they are imported in different modules but I would avoid it as it would be confusing.

Regards,
Arnaud.
Reply all
Reply to author
Forward
0 new messages