This commit is contained in:
ExostFlash 2025-11-26 11:48:06 +01:00
parent 8e9bd1a6d0
commit fec717628c
4 changed files with 63 additions and 2 deletions

View file

@ -1 +1,15 @@
<p>home works!</p> <h1>home works!</h1>
<h2>Task List</h2>
<ng-container *ngIf="tasks$ | async as tasks; else loading">
<ul>
<li *ngFor="let task of tasks">
{{ task.title }}
</li>
</ul>
</ng-container>
<ng-template #loading>
<p>Loading tasks...</p>
</ng-template>
<p>Temps écoulé : {{ count / 2 }} secondes</p>

View file

@ -1,11 +1,28 @@
import { Component } from '@angular/core'; import { Component } from '@angular/core';
import { CommonModule, AsyncPipe } from '@angular/common';
import { TaskService } from '../../service/task.service';
@Component({ @Component({
selector: 'app-home', selector: 'app-home',
imports: [], imports: [CommonModule, AsyncPipe],
templateUrl: './home.component.html', templateUrl: './home.component.html',
styleUrl: './home.component.css' styleUrl: './home.component.css'
}) })
export class HomeComponent { export class HomeComponent {
protected count = 0;
tasks$!: ReturnType<TaskService['getTasks']>;
constructor(private taskService: TaskService) {
this.tasks$ = this.taskService.getTasks();
}
ngOnInit() {
setInterval(() => {
this.count++;
console.log(this.count);
}, 500);
}
} }

View file

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { TaskService } from './task.service';
describe('TaskService', () => {
let service: TaskService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(TaskService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View file

@ -0,0 +1,14 @@
import { Injectable } from '@angular/core';
import { of } from 'rxjs';
import { delay } from 'rxjs/operators';
@Injectable({
providedIn: 'root'
})
export class TaskService {
private tasks = [{id: 1 , title: 'Sample Task'}, {id: 2, title: 'Another Task'}, {id: 3, title: 'More Tasks'}];
getTasks() {
return of(this.tasks).pipe(delay(1000));
}
}