Demonstrates common ways to pass data between Angular components:
- Parent-to-child communication with
@Input() - Child-to-parent communication with
@Output()andEventEmitter - Sibling communication through a shared RxJS service
- Angular 21
- TypeScript 5.9
- RxJS 7
- Bootstrap 5
- Jest for unit tests
- Angular ESLint for linting
- GitHub Actions for CI
Use a Node.js version supported by Angular 21:
- Node.js
20.19+,22.12+, or24.x - npm 10+
This repo was verified locally with Node.js 22.21.1.
npm installnpm startOpen http://localhost:4200.
| Command | Description |
|---|---|
npm start |
Start the Angular dev server |
npm run build |
Build the app into dist/ |
npm run lint |
Run Angular ESLint |
npm test |
Run Jest tests once |
npm run test:watch |
Run Jest in watch mode |
npm run test:coverage |
Run Jest with coverage output |
HomeComponent passes values into child components.
<app-student [parentData]="parentData"></app-student>
<app-courses [parentData]="parentText.value"></app-courses>StudentComponent and CoursesComponent receive the value through an input.
@Input() parentData = '';StudentComponent emits text changes to its parent.
@Output() childEvent = new EventEmitter<string>();
onChange(value: string) {
this.childEvent.emit(value);
}HomeComponent receives the emitted value.
<app-student (childEvent)="childData=$event"></app-student>CommunicationService stores the shared counter and exposes events.
private counterSource = new BehaviorSubject<number>(0);
currentCounter = this.counterSource.asObservable();
updateCounter(count: number) {
this.counterSource.next(count);
}StudentComponent increases the counter, while CoursesComponent can decrease it. HomeComponent listens to both event streams and updates its display.
The project uses Jest instead of Karma/Jasmine. Current coverage includes:
CommunicationServicecounter and event streamsCoursesServicedataStudentComponentinput/output and counter behaviorCoursesComponentservice data rendering and counter behaviorHomeComponentservice event handling and child output handling- Smoke test coverage
Run tests with:
npm test -- --ciGitHub Actions runs on every push to main and every pull request targeting main.
The CI pipeline runs:
npm ci
npm run lint
npm test -- --ci
npm run buildWorkflow file:
.github/workflows/ci.yml