3

i have a component contractDetails in contract module, i want to use this component in another module

i tried to export the contractDetails component but i get this error

If 'contract-details' is an Angular component, then verify that it is part of this module.

contract.module.ts

 @NgModule({
        imports: [
            CommonModule,
            ContractRoutingModule
        ],
        exports: [
            ContractDetailsComponent
        ],
        declarations: [
            ContractDetailsComponent
        ]
    })
    export class ContractModule { }

contract-details.component.ts

@Component({
        selector: 'contract-details',
        templateUrl: './contract-details.component.html'
    })
    export class ContractDetailsComponent {

    }

organization.module.ts

@NgModule({
    imports: [
        CommonModule,
        OrganizationRoutingModule
    ],
    declarations: [
        OrganizationDetailsComponent
    ]
})
export class OrganizationModule { }

organization-details.component.ts

@Component({
    templateUrl: './organization-details.component.html',
    styleUrls: ['./organization-details.component.scss']
})
export class OrganizationDetailsComponent {
}

organization-details.component.html

<contract-details></contract-details>
3
  • 1
    Possible duplicate of Angular 2 Use component from another module Commented Jan 10, 2019 at 14:25
  • import ContractModule in your organization module. Commented Jan 10, 2019 at 14:48
  • @Igor this is not a duplicate. The question you linked has a different use case where he wants to use a component from a sub module while in this question, he wants to use a component from a sibling module. Commented Feb 18, 2021 at 1:32

1 Answer 1

3

The OrganizationModule needs to import the ContractModule to be able to use the ContractDetailsComponent. The OrganizationModule definition should be:

@NgModule({
  imports: [
    CommonModule,
    OrganizationRoutingModule,
    ContractModule,
  ],
  declarations: [
    OrganizationDetailsComponent
  ]
})
export class OrganizationModule { }
Sign up to request clarification or add additional context in comments.

1 Comment

If for some reason he needs to import OrganizationModule into ContractModule then there will be circular dependency

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.