[英]pass params from one page to another in angular ionic
I want to pass params from signup page to signupotp page.我想将参数从注册页面传递到 signupotp 页面。 In my signupotp page otp is not getting recognised because of the params (email and mobile)is not getting passed to signupotp page.
在我的 signupotp 页面中,由于参数(电子邮件和移动设备)未传递到 signupotp 页面,因此无法识别 otp。 My backedn is coded like for otp verification params (mobile,emaail,otp) should be verified.So its not getting working properly.
我的 backedn 编码类似于 otp 验证参数(移动、电子邮件、otp)应该被验证。所以它不能正常工作。 I tried to initialise my data in signup page and passed to signupotp page.But not working.
我试图在注册页面中初始化我的数据并传递给 signupotp 页面。但没有工作。 How to do this?
这个怎么做?
SIGNUP.PAGE.TS SIGNUP.PAGE.TS
import { Component, OnInit } from '@angular/core';
import {ApiService} from '../api.service';
import{Router} from '@angular/router';
import { FormsModule } from '@angular/forms';
import {SignupotpPage} from '../signupotp/signupotp.page';
@Component({
selector: 'app-signup',
templateUrl: './signup.page.html',
styleUrls: ['./signup.page.scss'],
})
export class SignupPage implements OnInit {
Mobile:any;
Email:any;
data:any;
otp:any;
checked:any;
constructor(private api:ApiService,private router:Router,public signupotp:SignupotpPage) {}
ngOnInit() {
}
Continue(Mobile,Email){
const user= {
Mobile:Mobile,
Email:Email
}
console.log(Mobile);
console.log(Email);
this.api.SignupUser(user).subscribe(data=>{
console.log(data);
this.signupotp.initialisedata(Mobile,Email);
this.router.navigate(['signupotp']);
});
}
}
SIGNUPOTP.PAGE.TS SIGNUPOTP.PAGE.TS
import { Component, OnInit } from '@angular/core';
import {ApiService} from '../api.service';
import{Router} from '@angular/router';
@Component({
selector: 'app-signupotp',
templateUrl: './signupotp.page.html',
styleUrls: ['./signupotp.page.scss'],
})
export class SignupotpPage implements OnInit {
Mobile:any;
Email:any;
otp:any;
data:any;
constructor(private api:ApiService,private router:Router) {
}
initialisedata(email,mobile)
{
console.log("HUUUU");
console.log(email,mobile);
this.Email = email;
this.Mobile = mobile;
}
ngOnInit() {
}
Confirm(otp){
const user= {
otp:otp,
mobile:this.Mobile,
email:this.Email
}
console.log(otp);
console.log("hey how are you")
this.api.Verifysignupotp(user).subscribe(data=>{
console.log(data);
this.data = data;
if(this.data.Msg)
{
alert(this.data.Msg);
}
else
{
this.router.navigate(['/']);
}
});
}
}
Service.ts服务.ts
SignupUser(user):Observable<Object>{
console.log(user);
console.log('getting the signup data from user');
return this.http.post<Object>(`${this.base_url}/signup`,user);
}
Verifysignupotp(user): Observable<Object>{
console.log(user);
console.log('getting all Listing from the server');
return this.http.post<Object>(`${this.base_url}/verifysignupotp`,user);
}
There are ways in angular to pass parameters over the url of the route like this: this.router.navigate[‚path', param]
In your app-routing.module.ts you have to write something like this:在 angular 中有一些方法可以通过路径的 url 传递参数,如下所示:
this.router.navigate[‚path', param]
在您的 app-routing.module.ts 中,您必须编写如下内容:
export const routes: Routes = [
{ path: 'path/:param', component: yourComponent }
];
Or you just write the parameters on some variables in your signup Service and read them from wherever you want to use them.或者您只需在注册服务中的某些变量上写入参数,然后从您想使用它们的任何地方读取它们。
In your case I would create a object called user
in your service.ts.在您的情况下,我将在您的 service.ts 中创建一个名为
user
的 object。 When you get the data in your signup Component/Page you write it on the user
Object at your service.ts After navigating to your singupotp Page/Component you can read the data from the service and maybe extend the object with some other data.当您在注册组件/页面中获取数据时,您将其写入
user
Object 在您的 service.ts 导航到您的 singupotp 页面/组件后,您可以从服务中读取数据,并可能使用其他一些数据扩展 object。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.