[英]How To pass Some value from a form page To another using Angular2
I have two forms (register and login) Features:When the user clicks on the register button the data will be stored in an array that is in register.component.ts after it is redirected to the login page it must connect by its data entered in the register page How to pass the values from forms To another??please ?? 我有两种形式(注册和登录)功能:当用户单击注册按钮时,数据将被重定向到登录页面后存储在register.component.ts中的数组中,它必须通过输入的数据进行连接在注册页面中,如何将表单中的值传递给另一个? PS: I use angular2thank you in advance
PS:我事先使用angular2谢谢
利用Shared Services
在组件之间传递数据,甚至可以出于这些目的利用event emitters
import {Injectable, Injector} from '@angular/core';
@Injectable()
export class DataService {
data;
constructor() {}
}
in your component 在你的组件中
constructor(private dataService: DataService ){}
this.dataService.data= somedata;
in the other component 在其他组件中
constructor(private dataService: DataService ){}
somedata= this.dataService.data;
remember to register your ap in the providers of the module being used; 记住在使用的模块的提供者中注册您的ap;
providers: [DataService]
this can be used because the service injected in both components will be a singleton 可以使用此方法,因为在两个组件中注入的服务都是单例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.