Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript navTrl.push()中的承诺错误_Javascript_Angular_Typescript_Ionic2_Ionic3 - Fatal编程技术网

Javascript navTrl.push()中的承诺错误

Javascript navTrl.push()中的承诺错误,javascript,angular,typescript,ionic2,ionic3,Javascript,Angular,Typescript,Ionic2,Ionic3,我正在尝试构建一个简单的功能,让我可以在我的应用程序中浏览不同的页面。我希望能够在html代码中传递我想去的页面的名称。到目前为止我所做的是 在我家 `goToPage(test){ console.log('clicked! '+test); this.navCtrl.push(test); }` 在我的家里 <button ion-fab color="light" (click)='goToPage("ChooseCharacterPage")'> 所有

我正在尝试构建一个简单的功能,让我可以在我的应用程序中浏览不同的页面。我希望能够在html代码中传递我想去的页面的名称。到目前为止我所做的是

在我家

`goToPage(test){
    console.log('clicked! '+test);
    this.navCtrl.push(test);
}`
在我的家里

<button ion-fab color="light" (click)='goToPage("ChooseCharacterPage")'>

所有东西都会加载,但当我单击时,我会

invalid page component: ChooseCharacterPage
convertToView @ nav-util.js:23
NavControllerBase.push @ nav-controller-base.js:54
HomePage.goToPage @ home.ts:19
View_HomePage0.handleEvent_13 @ /AppModule/HomePage/component.ngfactory.js:193
(anonymous) @ view.js:408
(anonymous) @ dom_renderer.js:276
t.invokeTask @ polyfills.js:3
onInvokeTask @ ng_zone.js:227
t.invokeTask @ polyfills.js:3
e.runTask @ polyfills.js:3
invoke @ polyfills.js:3
error_handler.js:47 EXCEPTION: Uncaught (in promise): false
ErrorHandler.handleError @ error_handler.js:47
IonicErrorHandler.handleError @ ionic-error-handler.js:56
next @ application_ref.js:272
schedulerFn @ async.js:82
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:74
NgZone.triggerError @ ng_zone.js:278
onHandleError @ ng_zone.js:257
t.handleError @ polyfills.js:3
e.runGuarded @ polyfills.js:3
r @ polyfills.js:3
i @ polyfills.js:3
invoke @ polyfills.js:3
error_handler.js:52 ORIGINAL STACKTRACE:
ErrorHandler.handleError @ error_handler.js:52
IonicErrorHandler.handleError @ ionic-error-handler.js:56
next @ application_ref.js:272
schedulerFn @ async.js:82
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:74
NgZone.triggerError @ ng_zone.js:278
onHandleError @ ng_zone.js:257
t.handleError @ polyfills.js:3
e.runGuarded @ polyfills.js:3
r @ polyfills.js:3
i @ polyfills.js:3
invoke @ polyfills.js:3
error_handler.js:53 Error: Uncaught (in promise): false
    at s (polyfills.js:3)
    at polyfills.js:3
    at Object.ti.reject (nav-controller-base.js:187)
    at NavControllerBase._queueTrns (nav-controller-base.js:197)
    at NavControllerBase.push (nav-controller-base.js:52)
    at HomePage.goToPage (home.ts:19)
    at CompiledTemplate.proxyViewClass.View_HomePage0.handleEvent_13 (/AppModule/HomePage/component.ngfactory.js:193)
    at CompiledTemplate.proxyViewClass.<anonymous> (view.js:408)
    at HTMLButtonElement.<anonymous> (dom_renderer.js:276)
    at t.invokeTask (polyfills.js:3)
ErrorHandler.handleError @ error_handler.js:53
IonicErrorHandler.handleError @ ionic-error-handler.js:56
next @ application_ref.js:272
schedulerFn @ async.js:82
SafeSubscriber.__tryOrUnsub @ Subscriber.js:223
SafeSubscriber.next @ Subscriber.js:172
Subscriber._next @ Subscriber.js:125
Subscriber.next @ Subscriber.js:89
Subject.next @ Subject.js:55
EventEmitter.emit @ async.js:74
NgZone.triggerError @ ng_zone.js:278
onHandleError @ ng_zone.js:257
t.handleError @ polyfills.js:3
e.runGuarded @ polyfills.js:3
r @ polyfills.js:3
i @ polyfills.js:3
invoke @ polyfills.js:3
无效的页面组件:选择CharacterPage
convertToView@nav util.js:23
NavControllerBase.push@nav controller base.js:54
HomePage.goToPage@home.ts:19
查看_HomePage0.handleEvent_13@/AppModule/HomePage/component.ngfactory.js:193
(匿名)@view.js:408
(匿名)@dom_.js:276
t、 invokeTask@polyfills.js:3
onInvokeTask@ng_zone.js:227
t、 invokeTask@polyfills.js:3
e、 runTask@polyfills.js:3
调用@polyfills.js:3
error_handler.js:47异常:未捕获(承诺中):false
ErrorHandler.handleError@error_handler.js:47
IonicErrorHandler.handleError@ionic error handler.js:56
下一个@application_ref.js:272
schedulerFn@async.js:82
SafeSubscriber.\uuu tryorunsubscriber@Subscriber.js:223
SafeSubscriber.next@Subscriber.js:172
订户。_next@Subscriber.js:125
Subscriber.next@Subscriber.js:89
Subject.next@Subject.js:55
EventEmitter.emit@async.js:74
NgZone.triggerror@ng_zone.js:278
onHandleError@ng_zone.js:257
t、 handleError@polyfills.js:3
e、 runguared@polyfills.js:3
r@polyfills.js:3
i@polyfills.js:3
调用@polyfills.js:3
错误_handler.js:52原始堆栈跟踪:
ErrorHandler.handleError@error\u handler.js:52
IonicErrorHandler.handleError@ionic error handler.js:56
下一个@application_ref.js:272
schedulerFn@async.js:82
SafeSubscriber.\uuu tryorunsubscriber@Subscriber.js:223
SafeSubscriber.next@Subscriber.js:172
订户。_next@Subscriber.js:125
Subscriber.next@Subscriber.js:89
Subject.next@Subject.js:55
EventEmitter.emit@async.js:74
NgZone.triggerror@ng_zone.js:278
onHandleError@ng_zone.js:257
t、 handleError@polyfills.js:3
e、 runguared@polyfills.js:3
r@polyfills.js:3
i@polyfills.js:3
调用@polyfills.js:3
error_handler.js:53 error:Uncaught(承诺中):false
在s(polyfills.js:3)
在polyfills.js:3
at Object.ti.reject(导航控制器base.js:187)
在NavControllerBase.\u队列Trns(nav controller base.js:197)
在NavControllerBase.push(nav controller base.js:52)
在HomePage.goToPage(home.ts:19)
在CompiledTemplate.proxyViewClass.View_HomePage0.handleEvent_13(/AppModule/HomePage/component.ngfactory.js:193)中
在CompiledTemplate.proxyViewClass上。(view.js:408)
在HTMLButtoneElement。(dom_renderer.js:276)
在t.invokeTask(polyfills.js:3)
ErrorHandler.handleError@error_handler.js:53
IonicErrorHandler.handleError@ionic error handler.js:56
下一个@application_ref.js:272
schedulerFn@async.js:82
SafeSubscriber.\uuu tryorunsubscriber@Subscriber.js:223
SafeSubscriber.next@Subscriber.js:172
订户。_next@Subscriber.js:125
Subscriber.next@Subscriber.js:89
Subject.next@Subject.js:55
EventEmitter.emit@async.js:74
NgZone.triggerror@ng_zone.js:278
onHandleError@ng_zone.js:257
t、 handleError@polyfills.js:3
e、 runguared@polyfills.js:3
r@polyfills.js:3
i@polyfills.js:3
调用@polyfills.js:3

让我困惑的是承诺问题,因为变量是通过点击按钮传递的。只有当var未定义时,才应该出现承诺问题吗?

您没有在代码中的
单击
事件中传递
选择字符页

<button ion-fab color="light" (click)='goToPage("ChooseCharacterPage")'>

您没有在代码中的
单击
事件中传递
选择字符页

<button ion-fab color="light" (click)='goToPage("ChooseCharacterPage")'>

正如@suraj所说,您需要向push方法发送组件(而不是字符串)。但可能更简单的方法是在ts代码中声明属性,分配
ChooseCharacterPage
组件类:

public chooseCharacterPage: any = ChooseCharacterPage;

// ...

goToPage(test: any){
    this.navCtrl.push(test);
}
然后在您的视图中,您可以使用该变量:

<button ion-fab color="light" (click)='goToPage(chooseCharacterPage)'>


请注意,在html中,我们现在使用的是属性(名称以小写字母开头,不在引号之间)。

正如@suraj所说,您需要向push方法发送一个组件(而不是字符串)。但可能更简单的方法是在ts代码中声明属性,分配
ChooseCharacterPage
组件类:

public chooseCharacterPage: any = ChooseCharacterPage;

// ...

goToPage(test: any){
    this.navCtrl.push(test);
}
然后在您的视图中,您可以使用该变量:

<button ion-fab color="light" (click)='goToPage(chooseCharacterPage)'>


请注意,在html中,我们现在使用的是属性(名称以小写字母开头,不在引号之间)。

如果去掉引号,则变量未定义,如果将id直接添加到函数中,则必须为应用程序中的每个页面创建一个函数。难道没有办法将变量传递给push()吗?也许像stringfy()这样的东西可以将我的字符串转换成push可以识别的值?也许可以在函数中创建一个开关映射。将字符串文字映射到页面类否..它需要直接使用页面类..将使用示例编辑答案谢谢您的帮助,但是这样做我将不得不编写比为每个页面创建不同函数更多的代码。好的。。我想@sebafereras的答案应该适合你。设置一个带有页面的localvariable如果我去掉引号,该变量是未定义的,如果我将id直接添加到函数中,我将不得不为我的应用程序中的每个页面创建一个函数。难道没有办法将变量传递给push()吗?也许像stringfy()这样的东西可以将我的字符串转换成push可以识别的值?也许可以在函数中创建一个开关映射。将字符串文字映射到页面类否..它需要直接使用页面类..将使用示例编辑答案谢谢您的帮助,但是这样做我将不得不编写比为每个页面创建不同函数更多的代码。好的。。我想@sebafereras的答案应该适合你。使用页面设置localvariable这不是承诺问题。错误消息在第一行。这不是承诺问题。错误消息在第一行。这看起来像一个整洁的解决方案