One of the functionalities in my webpage involves a button that triggers the creation of a modal upon being clicked.
Now, I am looking to initialize a variable within the modal and then pass it back to the page containing the button once the modal is closed.
Here's an excerpt showcasing my attempt at achieving this (boilerplate code has been excluded):
modal.ts
myVar: string;
constructor(private navCtrl: NavController, private viewCtrl: ViewController) {
this.myVar = "Hello";
}
// code snippet for when the modal is closed
onCancel() {
this.viewCtrl.dismiss(this.myVar);
}
pageWithButton.ts
varFromModal: string;
constructor(private navCtrl: NavController, private viewCtrl: ViewController) {}
// Error encountered here: Error TS1068: Unexpected token. A constructor, method, accessor, or property was expected.
this.viewCtrl.onDismiss(data => {
this.varFromModal = data;
});