From 9d60e38dad32a3836617302391b51166ec4f022f Mon Sep 17 00:00:00 2001 From: zzz701 Date: Wed, 18 Jun 2025 22:40:28 +0800 Subject: [PATCH] call back Signed-off-by: zzz701 --- .../entry/src/main/ets/entryability/EntryAbility.ets | 4 ++-- code/HelloWorld/entry/src/main/ets/models/MyCallback.ets | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/code/HelloWorld/entry/src/main/ets/entryability/EntryAbility.ets b/code/HelloWorld/entry/src/main/ets/entryability/EntryAbility.ets index 5158b13b6f..86a9ad622a 100644 --- a/code/HelloWorld/entry/src/main/ets/entryability/EntryAbility.ets +++ b/code/HelloWorld/entry/src/main/ets/entryability/EntryAbility.ets @@ -15,10 +15,10 @@ class EntryAbility extends UIAbility { onWindowStageCreate(windowStage: window.WindowStage): void { hilog.info(0x0000, 'testTag', 'EntryAbility onWindowStageCreate'); try { - windowStage.loadContent('pages/Index', (err: BusinessError): void => { + windowStage.loadContent('pages/Index', (err: BusinessError | null): void => { hilog.info(0x0000, 'testTag', 'loadContent entering'); MyCallback.runCasesOfCallback(); - if (err.code) { + if (err && err.code) { hilog.info(0x0000, 'testTag', 'loadContent error'); return; } diff --git a/code/HelloWorld/entry/src/main/ets/models/MyCallback.ets b/code/HelloWorld/entry/src/main/ets/models/MyCallback.ets index 5827b846dc..5bdf82c967 100644 --- a/code/HelloWorld/entry/src/main/ets/models/MyCallback.ets +++ b/code/HelloWorld/entry/src/main/ets/models/MyCallback.ets @@ -28,8 +28,10 @@ export class MyCallback { MyCallback.myCallback((data: string) => { hilog.info(0x0000, 'testTag', 'MyCallback' + data); }) - MyCallback.myAsyncCallback((error: BusinessError, result: string) => { - hilog.info(0x0000, 'testTag', `myAsyncCallback, error: ${error.message}, result:${result}`); + MyCallback.myAsyncCallback((error: BusinessError | null, result: string | undefined) => { + if (error && result) { + hilog.info(0x0000, 'testTag', `myAsyncCallback, error: ${error.message}, result:${result}`); + } }) MyCallback.myErrorCallback((error: BusinessError) => { hilog.info(0x0000, 'testTag', `myAsyncCallback, error: ${error.message}`); -- Gitee