Open web-dave opened 2 years ago
(Pro Nav-Link eine)
ng g component swapi/film
src
Angular Generator
Component
film
src/app/swapi
SwapiModule
declarations
ActivatedRoute
Generiere 6 neue Angular Components aber diesmal für einzelne Entitäten.
(Pro Nav-Link eine)
Lokal
Online
src
Ordner in der Projekt Section.Angular Generator
Component
auswählenfilm
im Promt eingeben und bestätigensrc/app/swapi
verschiebenSwapiModule
indeclarations
array eintragenRouting
ActivatedRoute
holen (DI)Routing example
## SwapiRouting ```ts { path: 'films/:id', component: FilmComponent, }, ```Service
## ApiService ```ts getElement( name: 'films' | 'people' | 'planets' | 'species' | 'starships' | 'vehicles', id: number ) { return this.http.getDetails example
## FilmComponent ```ts export class FilmComponent implements OnInit { film: any; constructor(private route: ActivatedRoute, private api: ApiService) {} ngOnInit(): void { this.api .getElement('films', this.route.snapshot.params['id']) .subscribe((data) => (this.film = data)); } } ```