D
D
danila_prokopenko2021-07-05 20:25:41
Angular
danila_prokopenko, 2021-07-05 20:25:41

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 H4FoMUAJ3hk.jpg?size=1860x981&quality=96&sign=4de76661737d7a29c40d4381071d38e2&type=album
Viewing a single hero by id isBqv8QecQvCk.jpg?size=1856x980&quality=96&sign=d3fdb6bbfeb0d17767519290c4cf8847&type=album

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());
  }
}

Removal too.

But how to implement a wish list? Click on the button under the name of the hero, let's say "add to wishlist" => take his ID, redirect to a new page, referred to as "wishlist" => already in it, capturing the adishnik, parses the info and displays each hero whose button is pressed "Add to Wishlist" button.
Can you help?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lssssssssssl, 2021-07-05
@danila_prokopenko

  1. Взял готовый код из туториала
  2. Создал liked-component
  3. Добавил ссылку Liked Heroes в app-component
  4. Добавил кнопку save to your liked heroes в details-component
  5. Изменил интерфейс Hero путём добавления liked: boolean
  6. Изменил массив HEROES, добавив каждому объекту liked: false
  7. Что и для чего я поменял в методах, надеюсь, сами разберётесь

Решение не лучшее, зато очень доступное :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question