我正在使用 Ionic 4 创建一个聊天页面,我试图让它自动滚动到页面底部。我是这样做的,但它不起作用:
import { IonContent } from "@ionic/angular";
export class ChatroomPage implements OnInit {
messageForm: FormGroup;
messages: any[];
messenger: any;
@ViewChild(IonContent) content: IonContent;
constructor(
private navExtras: NavExtrasService,
private api: RestApiService,
private httpNative: HTTP
) { }
ngOnInit() {
this.content.scrollToBottom(300);
}
}
Run Code Online (Sandbox Code Playgroud)
在 html 文件中:
<ion-header>
<ion-toolbar color="primary">
<ion-title>Chatroom</ion-title>
</ion-toolbar>
</ion-header>
<!-- display previous message -->
<ion-content padding id="content">
<ion-list>
<ion-item *ngFor="let message of messages">
{{ message.message }}
</ion-item>
</ion-list>
</ion-content>
<!-- chat message input -->
<ion-footer>
<form [formGroup]="messageForm" …Run Code Online (Sandbox Code Playgroud) 我想将JSON对象传递给另一个页面。我尝试过的是使用Angular路由器传递JSON字符串,ActivatedRoute如下所示:
this.router.navigate(['details', details]);
Run Code Online (Sandbox Code Playgroud)
然后像这样检索它:
import { ActivatedRoute } from '@angular/router';
constructor(private activatedRoute: ActivatedRoute) {
}
ngOnInit() {
this.activatedRoute.params.subscribe(extras => {
console.log(extras);
this.JSONObject = extras;
});
}
Run Code Online (Sandbox Code Playgroud)
可以这样做,但是嵌套的JSON对象变得无法访问。它变成了这个字符串:
"[object Object]"
Run Code Online (Sandbox Code Playgroud)
字符串化的JSON对象很好,可以在我通过它之前进行访问。另一个问题是,它将JSON字符串附加到url,因此看起来不太好。从我的阅读中也可以看出,传递某种东西不仅仅是一种好id方法。
我在想类似在Android活动之间传递对象作为意图附加项的事情。我已经搜索了文档,论坛和以前的stackoverflow问题,但没有找到任何能使我实现这一目标的解决方案。使用Ionic4中的Angular路由器还有其他方法在页面之间传递对象吗?
我正在使用带有 Angular 路由器的 Ionic 4 开发应用程序。我想导航到另一个页面并清除页面堆栈。在Android原生中,它是这样的:
Intent intent = new Intent(NewActivity.this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
从我到目前为止所读到的内容来看,可以使用Ionic NavController但它在 Ionic 4 中已弃用。我了解了按钮,routerLink但如果我没有记错的话,通过使用该应用程序将立即导航到另一个页面。我需要在导航到另一个页面之前执行一些逻辑。
例如:登录页面。成功登录后,用户应该无法返回登录页面。此外,通过单击“登录”按钮,它应该调用一个函数来处理登录并决定导航/不导航到另一个页面。
有什么方法可以使用 Angular 路由器实现这一点,还是需要依赖已弃用的 Ionic NavController?