Skip to content

Instantly share code, notes, and snippets.

@YonathanMeguira
Last active July 26, 2018 14:15
Show Gist options
  • Save YonathanMeguira/3f84f25863164dce917a2db5d873fe3c to your computer and use it in GitHub Desktop.
Save YonathanMeguira/3f84f25863164dce917a2db5d873fe3c to your computer and use it in GitHub Desktop.
item.component.ts
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