简体   繁体   English

AngularJS在一个组件到另一个组件之间传输数据

[英]AngularJS transfer data between one component to another

Have some data for one controller JSON, I fill by this data in ng-repeat my view. 有一个控制器JSON的一些数据,我在ng-repeat视图中填充此数据。 But when selecting this data from view I need pass selected data to Form Controller fill all forms. 但是,当从视图中选择此数据时,我需要将所选数据传递给Form Controller填写所有表单。

I don't know how to do this in angularJS with components. 我不知道如何在带有组件的angularJS中执行此操作。 I built service, which parse data when i select it and pass to Form Controller. 我建立了服务,当我选择数据时将解析数据并传递给Form Controller。 But it's additional work parse it again by service.Maybe exist some more good way how pickup just id, and Form Controller load it automatically when get id's from service. 但是这是一项额外的工作,可以通过服务再次对其进行解析。也许还有一些更好的方式来提取ID,而从服务获取ID时,Form Controller会自动加载它。

AngularJS really hard for all ways as I understood :( 据我了解,AngularJS在所有方面都非常困难:(

It's better to provide some code samples with the question. 最好提供一些带有问题的代码示例。 Actually you have 3 main ways to share data between modules - parent controller, rootScope and services. 实际上,您有3种在模块之间共享数据的主要方法-父控制器,rootScope和服务。 Ok, there is event emitter here, but I heard opinions that it's not 'Angular way' to use events, because it's hard to maintain this architecture later. 好的,这里有事件发射器,但是我听到的观点是,使用事件不是“ Angular方式”,因为以后很难维护这种架构。 As I understood, you are using service for this porpoise and it's fine. 据我了解,您正在为此海豚使用服务,这很好。 Since Service is Singleton in Angular you can use it not only to share reusable peaces of code but and for sharing data between controllers. 由于Service是Angular中的Singleton,因此您不仅可以使用它来共享可重用的代码,而且可以在控制器之间共享数据。

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

相关问题 使用AngularJS服务将数据从一个html传输到另一个html(控制器之间的数据共享) - Transfer data from one html to another using AngularJS services (data share between controllers) 如何在反应中将数据从一个组件传输到另一个组件? - How to transfer data from one component to another in react? 无法以角度将一个组件之间的数据传递到另一个组件 - unable to pass data between one component to another component in angular 如何使用路由器/路由器参数将数据从一个父组件传输到另一个父组件 - How to transfer data from one parent component to another parent component in react using router / router params AngularJS-在HTML页面之间传输数据 - AngularJS - Transfer data between HTML pages 如何将数据传输/填充到 nextJS 中的另一个组件 - How to transfer/populate a data to another component in nextJS 我们如何在不使用Angular 2中的参数,查询参数和服务的情况下将数据对象从一个组件传输到另一组件 - How can we transfer data object from one component to another component without using params, queryparams and services in Angular 2 将数据从一页传输到另一页 - Transfer data from one page to another 将数据从一个 HTML 文件传输到另一个 - Transfer data from one HTML file to another 将一行数据从一个 object 转移到另一个 - Transfer a row of data from one object to another
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM