简体   繁体   English

在 angular 离子中将参数从一页传递到另一页

[英]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.

相关问题 将参数从一个组件传递到另一个angular2 - pass params from one component to another angular2 如何将数据从一个页面传递到另一个页面,以便在Ionic 2中进行导航 - How to pass data from one page to another for Navigation in Ionic 2 在ionic2中将项目单击中的变量从一页传递到另一页 - pass variable on item click from one page to another in ionic2 OnClick将项目从一页添加到另一页(Ionic 2 + Angular 2) - OnClick add items from one page to another (Ionic 2 + Angular 2) 将API数据从一页传递到另一页(Ionic 2 + Angular 2) - Passing API data from one page to another (Ionic 2 + Angular 2) 如何使用Ionic 3和NavController使用Angular 4将数据从一页传递到另一页。 我需要传递第一页到第二页的输入并调用API - How to pass data from one page to another page using Ionic 3 and Angular 4 using NavController. I need to pass input of 1st to 2nd page and callAPI 在 angular 10 中将变量从一页传递到另一页 - pass variable from one page to another in angular 10 如何在Angular中将值从一页传递到另一页? - How to pass the value from one page to another in Angular? 我可以在pop方法期间将参数从一页传递到另一页吗? 在离子2中 - Can i pass parameter from one page to another page during pop method ? In ionic 2 如何将数据从一页发送到另一页? 使用离子和 angular - How to send the data from one page to another page? using ionic and angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM