Answer the question
In order to leave comments, you need to log in
Wishlist in angular?
I'm new to angular, so sorry for the dumb question.
Went through the Tour of Heroes tutorial , using angular-in-memory-web-api and here is the question.
Accordingly, the display of heroes on the main screen is available
Viewing a single hero by id is
import { Hero } from '../hero';
import { HeroService } from '../hero.service';
@Component({
selector: 'app-hero-detail',
templateUrl: './hero-detail.component.html',
styleUrls: [ './hero-detail.component.scss' ]
})
export class HeroDetailComponent implements OnInit {
@Input() hero!: Hero;
constructor(
private route: ActivatedRoute,
private heroService: HeroService,
private location: Location
) {}
ngOnInit(): void {
this.getHero();
}
getHero(): void {
const id = +this.route.snapshot.paramMap.get('id')!;
this.heroService.getHero(id)
.subscribe(hero => this.hero = hero);
}
goBack(): void {
this.location.back();
}
save(): void {
this.heroService.updateHero(this.hero)
.subscribe(() => this.goBack());
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question