Skip to main content
InterviewHubPRO
Section Overview
Q229

Question 229 of 283

Part 9: NgModules, Providers, NgZone & Injector Hierarchies (213 - 255)

81%
Angular Master (283 Qs)•Part 9: NgModules, Providers, NgZone & Injector Hierarchies (213 - 255)

What are the steps to use declaration elements?

junior LevelCode ExampleDependency Injection

Below are the steps to be followed to use declaration elements.

  1. Create the element(component, directive and pipes) and export it from the file where you wrote it
  2. Import it into the appropriate module.
  3. Declare it in the @NgModule declarations array.

Practical Code Example

typescript
// Steps to use a declarable element across modules:
// 1. Declare in Module A
// 2. Export in Module A (exports: [MyComponent])
// 3. Import Module A into Module B