Skip to content

Instantly share code, notes, and snippets.

@haverchuck
Created June 19, 2018 16:26
Show Gist options
  • Save haverchuck/0a45184b2f6f8771fd93f3a3f6b54185 to your computer and use it in GitHub Desktop.
Save haverchuck/0a45184b2f6f8771fd93f3a3f6b54185 to your computer and use it in GitHub Desktop.
ionic-amplify-starter: list.item.modal.ts
import { Component, OnInit } from '@angular/core';
import { ModalController } from '@ionic/angular';
import { ToDoItem, ToDoList } from '../../classes/item.class';
@Component({
selector: 'item-modal',
templateUrl: 'list.item.modal.html',
})
export class ListItemModal implements OnInit {
itemList: ToDoList;
editItem: ToDoItem;
user: string;
item: ToDoItem;
constructor(private modalController: ModalController) {}
ngOnInit(){
/*
If we pass in an 'editItem' property, then we create a copy to store changes to the existing item
so that the original is not modified unless the user saves.
*/
this.item = this.editItem ? Object.assign({}, this.editItem) : new ToDoItem({})
}
save() {
this.modalController.dismiss({
itemList: this.itemList,
/*
We pass back either a newItem or editItem value depending on whether an edit operation is taking place
so that the list module can decide whether to insert into the items array or splice into it.
*/
newItem: !this.editItem ? this.item : null,
editItem: this.editItem ? this.item : null
});
};
cancel(){
this.modalController.dismiss({itemList: this.itemList})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment