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