将对象更新为新对象的实例

时间:2019-10-08 23:57:03

标签: javascript angular typescript

在Angular / typescript中,是否可以将列表中的对象实例更新为新对象,并在.html的绑定列表中显示更改?

  1. 我有一张纸牌。
  2. 我画了三张牌(以HTML显示)
  3. 绘制一张卡片并将列表中的第一张卡片更新为绘制的新卡片,即使我查看对象的数据已更新,该卡片也不会在HTML中得到更新。

代码:

// this works
this.Items[0] = this.Items[1]

//this does NOT work.
let newItem = new Item();
newItem.Id = x;
this.Items[0] = newItem; 


draw(deckId: string, count: number): Observable<Deck> {
  return this.http.get<Deck>(url).pipe(catchError(this.handleError));
}

drawThreeCards() {
   this.deckService.draw(this.deck.deck_id, 3).subscribe(data => {
   this.cards = data;
}

drawOneCards() {
    this.deckService.draw(this.deck.deck_id, 1).subscribe(data => {
    // Just as test I want to set the first card in the current
    // this.cards to the new card drawn

    let match = this.cards.find(x => x.Id == this.Items[0].code);
    match = this.data;
 }

0 个答案:

没有答案