angular - 离子 navCtrl.setPages 在 app.component.ts 中不起作用
问题描述
在我的 app.component.ts 文件中,如果用户点击 FCM 通知,我有一个代码会将用户发送到不同的页面。代码如下所示:
this.fcm.listenToNotifications().subscribe(async(notification) => {
if (notification.tap) {
const pages = [
{page: Page1},
{page: Page1Subpage, params: {...}}
];
this.navCtrl.setPages(pages);
this.navCtrl.parent.select(1);
}
当我执行通知时,我在 Xcode 编辑器中看到以下错误:
2019-01-17 16:55:13.230990+0200 Adservio[2103:800067] ERROR: Unhandled Promise rejection: null is not an object (evaluating 'this.navCtrl.setPages') ; Zone: <root> ; Task: Promise.then ; Value: TypeError: null is not an object (evaluating 'this.navCtrl.setPages') http://localhost:8080/var/containers/Bundle/Application/9301607C-7904-4404-B00D-FE8D9E7EED17/Adservio.app/www/build/main.js:1:1380986
有人知道为什么吗?
解决方案
这是相关文档:
如果您想从根应用程序组件控制导航怎么办?您不能注入NavController,因为作为导航控制器的任何组件都是根组件的子组件,因此它们不能被注入。
但是你可以使用导航
import { Nav } from 'ionic-angular';
//....
export class MyApp {
@ViewChild(Nav) nav: Nav;
//...
//And inside your function
//..
this.nav.push('Page1');
//..
推荐阅读
- python - 如何根据熊猫数据框中的多列值条件排除行?
- python - 在 scipy.stats.chisquare 中处理 NaN
- python - 如何使用 django 上的按钮 id 在引导模式上显示数据库中的动态内容
- powershell - 如何通过在命令行中执行脚本来使用 Powershell 获取 INI 节文件?
- c - 如何执行 .c 文件?
- php - 在hostgator中将表格发送到电子邮件
- python - 使用 xarray 将时间坐标从 UTC 转换为本地时区
- javascript - 如何为引导面板标题设置溢出-x
- google-apps-script - 如何根据特定的列条件将一些数据移动到另一个选项卡
- clickhouse - Clickhouse:有没有办法在一个“alter table drop partition ****”查询中删除多个分区?