Main component:
@Component({
selector: 'app-root',
template: '<app-report></app-report>'
})
Component 1:
@Component({
selector: 'app-report',
templateUrl: './trip.report.html'
})
Component2 :
@Component({
selector: 'app-report',
templateUrl: './user.report.html'
})
Is there any way in angular 4, through which based on some condition which component (component 1 or 2) will be loaded in "main component" based on some condition?
There is no way to do that. Selectors need to be unique for all components and directives declared within and imported into a single NgModule
.
If you own the code, just don't create conflicting selectors.
If imported 3rd-party modules have components with conflicting selectors,
you can wrap a conflicting component in another component with a non-conflicting selector and add it to it's own module.
Then you can specify in @NgModule({imports: [...]})
which component should be used.
Then you can just use *ngIf
<conflicting-component *ngIf="foo"></conflicting-component>
<de-conflicted-wrapper *ngIf="!foo"></de-conflicted-wrapper>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With