简体   繁体   English

如何使用Angular2将表单页面中的某些值传递给另一个

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

相关问题 如何在Angular2中将数据从一种形式传递到另一种形式 - How to Pass the Data from One form to Another Form in Angular2 Angular2:如何通过表单将值传递给另一个组件 - Angular2 : How to pass value through a form to another component 如何在Angular2中将变量值从一个组件传递到另一个组件 - How to pass variable value from one component to another in Angular2 如何在Angular2中将值从一个组件传递到另一个组件? - How to pass value from one component to another component in Angular2? 如何使用表单发布方法将参数从简单的 html 页面传递到另一个角度页面? - How to pass parameter from simple html page to another angular page using form post method? 如何在Angular中将值从一页传递到另一页? - How to pass the value from one page to another in Angular? 如何使用 angular 服务将表单值从一个组件传递到另一个组件中的列表? - How to pass form value from one component to a list in another component using angular services? 如何将(onchange)事件中的键和值从cshtml页面(视图)传递到angular2中的component(.ts)? - how to pass key and value in (onchange) event from cshtml page(view) to component(.ts) in angular2? 如何使用ts2代码从angular2 ui路由器将参数从一种状态传递到另一种状态? - how to pass parameters from one state to other using angular2 ui router form ts code? 如何将表单值传递给 angular 中的另一个组件 - how to pass form value to another component in angular
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM