add List heroes with *ngFor

This commit is contained in:
Костя 2025-06-18 12:31:54 +03:00
parent e1bca4a852
commit 26f1564df4
2 changed files with 17 additions and 8 deletions

View File

@ -1,6 +1,16 @@
<h2>{{hero.name | uppercase}} Details</h2> <!--h2>{{hero.name | uppercase}} Details</h2>
<div><span>id: </span>{{hero.id}}</div> <div><span>id: </span>{{hero.id}}</div>
<div> <div>
<label for="name">Hero name: </label> <label for="name">Hero name: </label>
<input id="name" [(ngModel)]="hero.name" placeholder="name"> <input id="name" [(ngModel)]="hero.name" placeholder="name">
</div> </div-->
<h2>My Heroes</h2>
<ul class="heroes">
<li *ngFor="let hero of heroes">
<button type="button">
<span class="badge">{{hero.id}}</span>
<span class="name">{{hero.name}}</span>
</button>
</li>
</ul>

View File

@ -2,6 +2,7 @@ import { Component } from '@angular/core';
import { Hero } from '../hero'; import { Hero } from '../hero';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms'; import { FormsModule } from '@angular/forms';
import {HEROES} from '../mock-heroes';
@Component({ @Component({
selector: 'app-heroes', selector: 'app-heroes',
@ -9,9 +10,7 @@ import { FormsModule } from '@angular/forms';
styleUrls: ['./heroes.component.css'], styleUrls: ['./heroes.component.css'],
imports: [CommonModule, FormsModule] imports: [CommonModule, FormsModule]
}) })
export class HeroesComponent {
hero: Hero = { export class HeroesComponent { //определяем класс со списком героев
id: 1, heroes = HEROES;
name: 'Windstorm'
};
} }