mirror of
https://github.com/Raghu-Ch/angular-challenges.git
synced 2026-02-10 12:53:03 -05:00
feat(injectionToken): create new challenge on injectionToken
This commit is contained in:
21
apps/angular/injection-token/src/app/app.component.ts
Normal file
21
apps/angular/injection-token/src/app/app.component.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { RouterLink, RouterOutlet } from '@angular/router';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [RouterOutlet, RouterLink],
|
||||
selector: 'app-root',
|
||||
template: ` <div class="flex gap-4 mb-5">
|
||||
<button class="border rounded-md px-4 py-2" routerLink="video">
|
||||
Video
|
||||
</button>
|
||||
<button class="border rounded-md px-4 py-2" routerLink="phone">
|
||||
Phone
|
||||
</button>
|
||||
</div>
|
||||
<router-outlet />`,
|
||||
host: {
|
||||
class: 'p-10 flex flex-col',
|
||||
},
|
||||
})
|
||||
export class AppComponent {}
|
||||
12
apps/angular/injection-token/src/app/app.config.ts
Normal file
12
apps/angular/injection-token/src/app/app.config.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { ApplicationConfig } from '@angular/core';
|
||||
import { provideRouter } from '@angular/router';
|
||||
|
||||
export const appConfig: ApplicationConfig = {
|
||||
providers: [
|
||||
provideRouter([
|
||||
{ path: '', pathMatch: 'full', redirectTo: 'video' },
|
||||
{ path: 'video', loadComponent: () => import('./video.component') },
|
||||
{ path: 'phone', loadComponent: () => import('./phone.component') },
|
||||
]),
|
||||
],
|
||||
};
|
||||
1
apps/angular/injection-token/src/app/data.ts
Normal file
1
apps/angular/injection-token/src/app/data.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const DEFAULT_TIMER = 1000;
|
||||
13
apps/angular/injection-token/src/app/phone.component.ts
Normal file
13
apps/angular/injection-token/src/app/phone.component.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { TimerContainerComponent } from './timer-container.component';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [TimerContainerComponent],
|
||||
template: `<div class="flex gap-2">
|
||||
Phone Call Timer:
|
||||
<p class="italic">(should be 2000s)</p>
|
||||
</div>
|
||||
<timer-container />`,
|
||||
})
|
||||
export default class PhoneComponent {}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { DEFAULT_TIMER } from './data';
|
||||
import { TimerComponent } from './timer.component';
|
||||
@Component({
|
||||
selector: 'timer-container',
|
||||
standalone: true,
|
||||
imports: [TimerComponent],
|
||||
template: `
|
||||
<div class="flex gap-2">
|
||||
Timer container:
|
||||
<p class="italic">(timer is {{ timer }}s)</p>
|
||||
</div>
|
||||
<timer />
|
||||
`,
|
||||
host: {
|
||||
class: 'border rounded-md flex p-4 gap-10',
|
||||
},
|
||||
})
|
||||
export class TimerContainerComponent {
|
||||
timer = DEFAULT_TIMER;
|
||||
}
|
||||
13
apps/angular/injection-token/src/app/timer.component.ts
Normal file
13
apps/angular/injection-token/src/app/timer.component.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { toSignal } from '@angular/core/rxjs-interop';
|
||||
import { interval } from 'rxjs';
|
||||
import { DEFAULT_TIMER } from './data';
|
||||
|
||||
@Component({
|
||||
selector: 'timer',
|
||||
standalone: true,
|
||||
template: ` Timer running {{ timer() }} `,
|
||||
})
|
||||
export class TimerComponent {
|
||||
timer = toSignal(interval(DEFAULT_TIMER));
|
||||
}
|
||||
13
apps/angular/injection-token/src/app/video.component.ts
Normal file
13
apps/angular/injection-token/src/app/video.component.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { Component } from '@angular/core';
|
||||
import { TimerContainerComponent } from './timer-container.component';
|
||||
|
||||
@Component({
|
||||
standalone: true,
|
||||
imports: [TimerContainerComponent],
|
||||
template: `<div class="flex gap-2">
|
||||
Video Call Timer:
|
||||
<p class="italic">(should be the default 1000s)</p>
|
||||
</div>
|
||||
<timer-container />`,
|
||||
})
|
||||
export default class VideoComponent {}
|
||||
0
apps/angular/injection-token/src/assets/.gitkeep
Normal file
0
apps/angular/injection-token/src/assets/.gitkeep
Normal file
BIN
apps/angular/injection-token/src/favicon.ico
Normal file
BIN
apps/angular/injection-token/src/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 15 KiB |
13
apps/angular/injection-token/src/index.html
Normal file
13
apps/angular/injection-token/src/index.html
Normal file
@@ -0,0 +1,13 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>angular-injection-token</title>
|
||||
<base href="/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico" />
|
||||
</head>
|
||||
<body>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
7
apps/angular/injection-token/src/main.ts
Normal file
7
apps/angular/injection-token/src/main.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { bootstrapApplication } from '@angular/platform-browser';
|
||||
import { appConfig } from './app/app.config';
|
||||
import { AppComponent } from './app/app.component';
|
||||
|
||||
bootstrapApplication(AppComponent, appConfig).catch((err) =>
|
||||
console.error(err)
|
||||
);
|
||||
5
apps/angular/injection-token/src/styles.scss
Normal file
5
apps/angular/injection-token/src/styles.scss
Normal file
@@ -0,0 +1,5 @@
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
/* You can add global styles to this file, and also import other style files */
|
||||
2
apps/angular/injection-token/src/test-setup.ts
Normal file
2
apps/angular/injection-token/src/test-setup.ts
Normal file
@@ -0,0 +1,2 @@
|
||||
import '@testing-library/jest-dom';
|
||||
import 'jest-preset-angular/setup-jest';
|
||||
Reference in New Issue
Block a user