Task
This commit is contained in:
parent
8e9bd1a6d0
commit
fec717628c
4 changed files with 63 additions and 2 deletions
|
|
@ -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>
|
||||
|
|
@ -1,11 +1,28 @@
|
|||
|
||||
import { Component } from '@angular/core';
|
||||
import { CommonModule, AsyncPipe } from '@angular/common';
|
||||
import { TaskService } from '../../service/task.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-home',
|
||||
imports: [],
|
||||
imports: [CommonModule, AsyncPipe],
|
||||
templateUrl: './home.component.html',
|
||||
styleUrl: './home.component.css'
|
||||
})
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
16
src/app/service/task.service.spec.ts
Normal file
16
src/app/service/task.service.spec.ts
Normal 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();
|
||||
});
|
||||
});
|
||||
14
src/app/service/task.service.ts
Normal file
14
src/app/service/task.service.ts
Normal 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));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue