Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i use different selector with same name?

Tags:

angular

For example, I have two module

(1) module 'A' - have a component 'list', selector 'list'

(2) module 'B' - also, have component 'list', selector 'list'

I wish to use both this 'list' component in my module's 'list' component is it possible?

If yes, then how can I use selector of those component?

like image 958
Dhaval Avatar asked Mar 07 '19 14:03

Dhaval


People also ask

Can I use multiple selectors in CSS?

A CSS selector can contain more than one simple selector. Between the simple selectors, we can include a combinator. There are four different combinators in CSS: descendant selector (space)

Can CSS have two classes with same name?

If you have two CSS files containing the same class name, then the properties of both will be applied in a sort of combination. If both class declarations share the same property, then the one for the file that was linked last is applied. Any properties that are declared in only one of the CSS files will be applied.

Can we combine two selectors?

The descendant combinator — typically represented by a single space (" ") character — combines two selectors such that elements matched by the second selector are selected if they have an ancestor (parent, parent's parent, parent's parent's parent, etc.) element matching the first selector.


1 Answers

If you want to use the list component from another list component and from different modules, you can do so by specifying entryComponents inside your Component or NgModule:

@Component({
  ...,
  entryComponents: [ AListComponent ]
})
export class BListComponent {}


or 


@NgModule({
  ...,
  entryComponents: [ AListComponent ]
})
export class ModuleB {}

BListComponent Template

   // You can then easily use & specify the AListComponent selector here
   <a-list-component></a-list-component>

But if those modules are merged and imported on a root module like

@NgModule({
  imports: [ AModule, BModule ]
})
export class RootModule {}

then on your ModuleA, you can just specify the component you need to export to be able to utilize it on other components

 @NgModule({
  ...,
  exports: [ AListComponent ]    // Export AListComponent to be utilized on BListComponent
})
export class ModuleA {}

BListComponent Template

<a-list-component></a-list-component>
like image 200
KShewengger Avatar answered Oct 12 '22 10:10

KShewengger