Last active
July 26, 2018 14:15
-
-
Save YonathanMeguira/3f84f25863164dce917a2db5d873fe3c to your computer and use it in GitHub Desktop.
item.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, OnInit, Input } from '@angular/core'; | |
import { ItemQuery, ListQuery, List, Item, ShopikaService } from '../state'; | |
import { ID } from '@datorama/akita'; | |
@Component({ | |
selector: 'app-edit', | |
templateUrl: './edit.component.html', | |
styleUrls: ['./edit.component.css'] | |
}) | |
export class EditComponent implements OnInit { | |
list: List; | |
@Input() listId: ID; | |
constructor(private itemQuery: ItemQuery, private listQuery: ListQuery, private service: ShopikaService) { } | |
ngOnInit() { | |
this.list = {...this.listQuery.getEntity(this.listId)}; | |
this.list.items = this.list.items.map((id: ID) => this.itemQuery.getEntity(id)); | |
} | |
saveItem(checked: boolean, id: ID) { | |
const item = {...this.list.items.filter((item: Item) => item.id === id)[0] as Item}; | |
item.purchased = checked; | |
this.service.updateItemStatus(item); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment