How to use closeCallback() function


#1

hello, everyone.

I am developing nativescript app now.
I have one error this morning.
In my app, I coded a custom modal dialog. next In the dialog, add a button and executed closeCallback() function in order to close the dialog.
I hope to close the dialog, but unfortunately, to close is my total app.
Please help me!
There is codes in below.
html of custom modal dialog view.

Label (tap)=“OnGoListPage()”>

type script file of custom modal dialog.

import {ModalDialogParams} from “nativescript-angular/modal-dialog”;
import { Page } from “ui/page”;

@Component({

selector: ‘modal-content1’,
templateUrl:“pages/inzenden/inzenden.html”,
styleUrls:[“pages/inzenden/inzenden-common.css”, “pages/inzenden/inzenden.css”]

})
export class InzendenComponent {
public prompt: string;

constructor(public params: ModalDialogParams, private page:Page) {
    this.prompt = params.context.promptMsg;
}

OnGoListPage(){
    this.params.closeCallback();////while this function are executed, my app was closed.

}
}
thanks for your attention.


#2

I am also looking for help with modal callbacks using Angular. Couldnt find any examples.

Can anyone help here?


#3

Check out


just in case you haven’t. It has examples for the most common scenarios, it is likely that you will find an answer there.


#4

Thanks Pete

It was more to do with use showingModally which seems to be available in the page tag, but not sure how to do in Angular??

Best


#5

const options: ModalDialogOptions = {
viewContainerRef: this.vcRef,
context: {
me: ‘sample text’,
},
fullscreen: false,
};
this.modalDialogService.showModal(SampleModalComponent, options)
.then(result => {
// result value is the string you attach in closeCallBack(‘cute’)
console.log(“result”, result);
})
.catch(error => {
console.log(“no response”);
});

I Hope this will help you.


#6

I have the same issue with my app. The custom dialog is shown when a user selects a switch, the dialog is displayed but then the application crashed on this.params.closeCallback() ;

CONSOLE ERROR [native code]: ERROR RangeError: Maximum call stack size exceeded.
CONSOLE ERROR [native code]: ERROR CONTEXT null
CONSOLE LOG file:///app/app.module.js:89:24: Error: RangeError: Invalid Date
***** Fatal JavaScript exception - application has been terminated. *****
Native stack trace:
1   0x10a82fc1f NativeScript::reportFatalErrorBeforeShutdown(JSC::ExecState*, JSC::Exception*, bool, bool)
2   0x10a8598ea NativeScript::FFICallback<NativeScript::ObjCMethodCallback>::ffiClosureCallback(ffi_cif*, void*, void**, void*)
3   0x10b226ced ffi_closure_unix64_inner
4   0x10b227642 ffi_closure_unix64
5   0x10c48c7a4 -[UIControl sendAction:to:forEvent:]
6   0x10c48cac1 -[UIControl _sendActionsForEvents:withEvent:]
7   0x10c48ba09 -[UIControl touchesEnded:withEvent:]
8   0x10c3860bf -[UIWindow _sendTouchesForEvent:]
9   0x10c3877c1 -[UIWindow sendEvent:]
10  0x10c32b310 -[UIApplication sendEvent:]
11  0x10cc6c6af __dispatchPreprocessedEventFromEventQueue
12  0x10cc6f2c4 __handleEventQueueInternal
13  0x10fe0dbb1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__
14  0x10fdf24af __CFRunLoopDoSources0
15  0x10fdf1a6f __CFRunLoopRun
16  0x10fdf130b CFRunLoopRunSpecific
17  0x113016a73 GSEventRunModal
18  0x10c310057 UIApplicationMain
19  0x10b22749d ffi_call_unix64
20  0x1342ae170
JavaScript stack trace:
1   toISOString@undefined:15:26
2   stringify@[native code]
3   @:15:26
4   error@[native code]
5   error@[native code]
6   View_ConfirmationDialogComponent_0@:10:75
7   logError@file:///app/tns_modules/@angular/core/bundles/core.umd.js:11113:31
8   @[native code]
9   handleError@file:///app/tns_modules/@angular/core/bundles/core.umd.js:1737:28
10  dispatchEvent@file:///app/tns_modules/@angular/core/bundles/core.umd.js:7521:47
11  @file:///app/tns_modules/nativescript-angular/renderer.js:185:31
12  onInvoke@file:///app/tns_modules/@angular/core/bundles/core.umd.js:3813:43
13  run@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:138:49
14  zonedCallback@file:///app/tns_modules/nativescript-angular/renderer.js:184:27
15  notify@file:///app/tns_modules/tns-core-modules/data/observable/observable.js:110:31
16  _emit@file:///app/tns_modules/tns-core-modules/data/observable/observable.js:127:24
17  tap@file:///app/tns_modules/tns-core-modules/ui/button/button.js:207:24
18  UIA<…>
JavaScript error:
undefined:15:26: JS ERROR RangeError: Invalid Date
CONSOLE LOG file:///app/app.module.js:89:24: Error: Error

I tried to reproduce it with a simpler app but couldn’t manage to reproduce the problem (https://play.nativescript.org/?template=play-ng&id=Yq1T2I)