简体   繁体   English

组件之间共享数据信息的Angular 4问题

[英]Angular 4 issue with sharing data information between components

I'm developing Angular 4 app, user registers with facebook and then redirects to form wizard, where he have to fill 5 forms step by step, on each step data will be saved ideally in an object and same object will keep record of previously filled all forms plus next coming forms. 我正在开发Angular 4应用程序,用户在facebook上注册,然后重定向到表单向导,他必须逐步填写5个表单,每一步中的数据将理想地保存在一个对象中,并且同一对象将保留以前填充的记录所有表格以及接下来的表格。

This page has: 该页面具有:

  1. HEADER (component) which contains HEADER(组件),其中包含

    • Logo 商标
    • Bullets to show active, currently active and disabled steps (component) 项目符号以显示活动,当前活动和禁用的步骤(组件)
    • Logged user name and image (component) 记录的用户名和图像(组件)
  2. SIDEBAR (component) 侧边栏(组件)

  3. CONTENT area which contains 包含的内容区域

    • Card (Component) having nested components for different Form 卡(组件)具有嵌套的不同表格的组件

I have to keep record of which step's form user is currently filling and how many have been filled so he can navigate back and forth up to the last form being filled, the other steps remain disabled until user reaches them filling one by one. 我必须保持记录用户当前正在填写哪个步骤以及已经填写了多少表格,以便他可以来回导航直到最后一个表格被填写,其他步骤保持禁用状态,直到用户到达他们一步一步地填写为止。

The content area has which loads card (component) and there's nested form (component). 内容区域具有用于加载卡片(组件)的嵌套区域和嵌套表格(组件)。

Issue is I'm not finding proper solution how to structure code so I can share data between all components to keep record of active and current steps, which are indicated on left sidebar and in the header bullets 问题是我没有找到适当的解决方案来构建代码,因此我无法在所有组件之间共享数据以保持活动和当前步骤的记录,这些记录在左侧边栏和标题项目符号中指示

following is layout of my page. 以下是我页面的布局。

在此处输入图片说明

You could use a Service which you share between all your components. 您可以使用在所有组件之间共享的服务

Basically what you do is, store the information in a place(the service) which then is injected in each component where you need the information. 基本上,您要做的是将信息存储在一个位置(服务)中,然后将该位置注入您需要信息的每个组件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM