Communication of non-parent-child components in ANGULARJS2

Source: Internet
Author: User
Tags export class

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.