From aa5c652cdf3803cc9f8cd0a5931ec6f1491cacf4 Mon Sep 17 00:00:00 2001 From: kiwi Date: Mon, 17 Mar 2025 17:06:47 +0100 Subject: [PATCH] succeed ngFor initialization --- .../src/app/app.component.html | 3 ++- .../src/app/app.component.ts | 3 ++- angular-tour-of-heroes/src/app/hero.ts | 4 ++++ .../src/app/heroes/heroes.component.html | 17 ++++++++++++++ .../src/app/heroes/heroes.component.scss | 0 .../src/app/heroes/heroes.component.spec.ts | 23 +++++++++++++++++++ .../src/app/heroes/heroes.component.ts | 20 ++++++++++++++++ angular-tour-of-heroes/src/app/mock-heroes.ts | 13 +++++++++++ 8 files changed, 81 insertions(+), 2 deletions(-) create mode 100644 angular-tour-of-heroes/src/app/hero.ts create mode 100644 angular-tour-of-heroes/src/app/heroes/heroes.component.html create mode 100644 angular-tour-of-heroes/src/app/heroes/heroes.component.scss create mode 100644 angular-tour-of-heroes/src/app/heroes/heroes.component.spec.ts create mode 100644 angular-tour-of-heroes/src/app/heroes/heroes.component.ts create mode 100644 angular-tour-of-heroes/src/app/mock-heroes.ts diff --git a/angular-tour-of-heroes/src/app/app.component.html b/angular-tour-of-heroes/src/app/app.component.html index 878358f..4381b87 100644 --- a/angular-tour-of-heroes/src/app/app.component.html +++ b/angular-tour-of-heroes/src/app/app.component.html @@ -1 +1,2 @@ -

Welcome to the {{ title }}

\ No newline at end of file +

Welcome to the {{ title }}

+ \ No newline at end of file diff --git a/angular-tour-of-heroes/src/app/app.component.ts b/angular-tour-of-heroes/src/app/app.component.ts index c5e2e21..fabe144 100644 --- a/angular-tour-of-heroes/src/app/app.component.ts +++ b/angular-tour-of-heroes/src/app/app.component.ts @@ -1,9 +1,10 @@ import { Component } from '@angular/core'; import { RouterOutlet } from '@angular/router'; +import { HeroesComponent } from './heroes/heroes.component'; @Component({ selector: 'app-root', - imports: [RouterOutlet], + imports: [RouterOutlet, HeroesComponent], templateUrl: './app.component.html', styleUrl: './app.component.scss' }) diff --git a/angular-tour-of-heroes/src/app/hero.ts b/angular-tour-of-heroes/src/app/hero.ts new file mode 100644 index 0000000..2849018 --- /dev/null +++ b/angular-tour-of-heroes/src/app/hero.ts @@ -0,0 +1,4 @@ +export interface Hero { + id: number; + name: string; +} \ No newline at end of file diff --git a/angular-tour-of-heroes/src/app/heroes/heroes.component.html b/angular-tour-of-heroes/src/app/heroes/heroes.component.html new file mode 100644 index 0000000..5c5084d --- /dev/null +++ b/angular-tour-of-heroes/src/app/heroes/heroes.component.html @@ -0,0 +1,17 @@ +

{{hero.name}} Details

+
id: {{hero.id}}
+
name: {{hero.name}}
+
+ + +
+ +

My Heroes

+ \ No newline at end of file diff --git a/angular-tour-of-heroes/src/app/heroes/heroes.component.scss b/angular-tour-of-heroes/src/app/heroes/heroes.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/angular-tour-of-heroes/src/app/heroes/heroes.component.spec.ts b/angular-tour-of-heroes/src/app/heroes/heroes.component.spec.ts new file mode 100644 index 0000000..0e9e4bb --- /dev/null +++ b/angular-tour-of-heroes/src/app/heroes/heroes.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { HeroesComponent } from './heroes.component'; + +describe('HeroesComponent', () => { + let component: HeroesComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [HeroesComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(HeroesComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/angular-tour-of-heroes/src/app/heroes/heroes.component.ts b/angular-tour-of-heroes/src/app/heroes/heroes.component.ts new file mode 100644 index 0000000..98651ad --- /dev/null +++ b/angular-tour-of-heroes/src/app/heroes/heroes.component.ts @@ -0,0 +1,20 @@ +import { Component } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { NgFor } from '@angular/common'; +import { Hero } from '../hero' +import { HEROES } from '../mock-heroes'; + + +@Component({ + selector: 'app-heroes', + imports: [FormsModule, NgFor], + templateUrl: './heroes.component.html', + styleUrl: './heroes.component.scss' +}) +export class HeroesComponent { + hero: Hero = { + id: 1, + name: 'Windstorm' + }; + heroes = HEROES; +} diff --git a/angular-tour-of-heroes/src/app/mock-heroes.ts b/angular-tour-of-heroes/src/app/mock-heroes.ts new file mode 100644 index 0000000..e6152ec --- /dev/null +++ b/angular-tour-of-heroes/src/app/mock-heroes.ts @@ -0,0 +1,13 @@ +import { Hero } from './hero'; + +export const HEROES: Hero[] = [ + { id: 12, name: 'Dr. Nice' }, + { id: 13, name: 'Bombasto' }, + { id: 14, name: 'Celeritas' }, + { id: 15, name: 'Magneta' }, + { id: 16, name: 'RubberMan' }, + { id: 17, name: 'Dynama' }, + { id: 18, name: 'Dr. IQ' }, + { id: 19, name: 'Magma' }, + { id: 20, name: 'Tornado' } +]; \ No newline at end of file