@@ -724,43 +724,43 @@ Then, we can use the `TodoService` to use the server-side HTTP APIs, as we'll do
724724Open the `/angular/src/app/home/home.component.ts` file and replace its content with the following code block:
725725
726726```ts
727- import { ToasterService } from "@abp/ng.theme.shared" ;
728- import { Component, OnInit, inject } from ' @angular/core ' ;
729- import { TodoItemDto } from "@proxy/services/dtos" ;
730- import { TodoService } from " @proxy/services" ;
727+ import {Component, inject, OnInit } from ' @angular/core ' ;
728+ import {FormsModule } from ' @angular/forms ' ;
729+ import { ToasterService } from ' @abp/ng.theme.shared ' ;
730+ import { TodoItemDto, TodoService } from ' @proxy' ;
731731
732732@Component({
733- selector: ' app-home' ,
734- templateUrl: ' ./home.component.html' ,
735- styleUrls: [' ./home.component.scss' ],
733+ selector: ' app-home' ,
734+ templateUrl: ' ./home.component.html' ,
735+ styleUrls: [' ./home.component.scss' ],
736+ imports: [FormsModule]
736737})
737738export class HomeComponent implements OnInit {
738739
739- todoItems: TodoItemDto[];
740- newTodoText: string;
740+ todoItems: TodoItemDto[];
741+ newTodoText: string;
742+ readonly todoService = inject(TodoService);
743+ readonly toasterService = inject(ToasterService);
741744
742- private readonly todoService = inject(TodoService);
743- private readonly toasterService = inject(ToasterService);
745+ ngOnInit(): void {
746+ this.todoService.getList().subscribe(response => {
747+ this.todoItems = response;
748+ });
749+ }
744750
745- ngOnInit(): void {
746- this.todoService.getList().subscribe(response => {
747- this.todoItems = response;
748- });
749- }
750-
751- create(): void {
752- this.todoService.create(this.newTodoText).subscribe((result) => {
753- this.todoItems = this.todoItems.concat(result);
754- this.newTodoText = null;
755- });
756- }
751+ create(): void{
752+ this.todoService.create(this.newTodoText).subscribe((result) => {
753+ this.todoItems = this.todoItems.concat(result);
754+ this.newTodoText = null;
755+ });
756+ }
757757
758- delete(id: string): void {
759- this.todoService.delete(id).subscribe(() => {
760- this.todoItems = this.todoItems.filter(item => item.id !== id);
761- this.toasterService.info(' Deleted the todo item.' );
762- });
763- }
758+ delete(id: string): void {
759+ this.todoService.delete(id).subscribe(() => {
760+ this.todoItems = this.todoItems.filter(item => item.id !== id);
761+ this.toasterService.info(' Deleted the todo item.' );
762+ });
763+ }
764764}
765765```
766766
@@ -772,30 +772,33 @@ Open the `/angular/src/app/home/home.component.html` file and replace its conten
772772
773773````html
774774<div class="container">
775- <div class="card">
776- <div class="card-header">
777- <div class="card-title">TODO LIST</div>
778- </div>
779- <div class="card-body">
780- <!-- FORM FOR NEW TODO ITEMS -->
781- <form class="row row-cols-lg-auto g-3 align-items-center" (ngSubmit)="create()">
782- <div class="col-12">
783- <div class="input-group">
784- <input name="NewTodoText" type="text" [(ngModel)]="newTodoText" class="form-control" placeholder="enter text..." />
785- </div>
775+ <div class="card">
776+ <div class="card-header">
777+ <div class="card-title">TODO LIST</div>
786778 </div>
787- <div class="col-12">
788- <button type="submit" class="btn btn-primary">Submit</button>
779+ <div class="card-body">
780+ <!-- FORM FOR NEW TODO ITEMS -->
781+ <form class="row row-cols-lg-auto g-3 align-items-center" (ngSubmit)="create()">
782+ <div class="col-12">
783+ <div class="input-group">
784+ <input name="NewTodoText" type="text" [(ngModel)]="newTodoText" class="form-control" placeholder="enter text..." />
785+ </div>
786+ </div>
787+ <div class="col-12">
788+ <button type="submit" class="btn btn-primary">Submit</button>
789+ </div>
790+ </form>
791+
792+ <!-- TODO ITEMS LIST -->
793+ <ul id="TodoList">
794+ @for (todoItem of todoItems; track todoItem.id) {
795+ <li>
796+ <i class="fa fa-trash-o" (click)="delete(todoItem.id)"></i> {{ todoItem.text }}
797+ </li>
798+ }
799+ </ul>
789800 </div>
790- </form>
791- <!-- TODO ITEMS LIST -->
792- <ul id="TodoList">
793- <li *ngFor="let todoItem of todoItems">
794- <i class="fa fa-trash-o" (click)="delete(todoItem.id)"></i> {%{{{ todoItem.text }}}%}
795- </li>
796- </ul>
797801 </div>
798- </div>
799802</div>
800803````
801804
0 commit comments