AngualrJs2 The official method is to @input, @Output to achieve the mutual value between components, and the components must be a parent-child relationship, the following gives you a simple way to achieve the transfer of values between components, not only the parent-child component, cross-module components can also achieve the value
/*/@Injectable () Export class prepservice{// define a property as a pass-through parameter between components , or it can be an object or method profileinfo:any; }
/** * * *. Pass the parameters of the component, my side of a simple demonstration, directly in the constructor to implement the parameters*/@Component ({selector:' XXXXXXX ', Templateurl:"./xxxxxx.html", styleurls:["./xxxxxxx.css"]}) Export class Reportcomponent {//define the parameters to be passed (here is an object, or a method)Reponseprep:any ={name:"Bacon bean Curd", Address:"Central Pork" } //Constructor Injection Prepservice serviceConstructor (private Ps:prepservice) {//assigns the current component parameter to the ProfileInfo property of the PrepservicePs.profileinfo = This. Reponseprep; } }
/* *. Components that accept parameters */ @Component ({selector: ' yyyyyy '
Idea: Defining a service as a vector for passing parameters is injected into the constructor of the component to which the parameter is being passed, and then assigning values and values to the service's inside attribute (the reference vector) to implement the arguments between the components.
This is a cool, any component can communicate between, for reference only, I am also NG2 rookie.
Communication of non-parent-child components in ANGULARJS2