I'm new to Angular 4 and trying to create a single page with 2 different view. Each of them have a component.ts, an html and a model. I don't understand how to share variables between the two views. For example, the first view has a search panel with a button, when I click this button I call a service(not clear where call the service if on the first or second component) that returns a resulset.The second one must appear only if a result is provided.Thanks.
Asked
Active
Viewed 892 times
0
-
I think that you want share data between components really? – IvanMoreno Nov 16 '17 at 13:33
-
Yes, correct. Can you help me? Thanks. – fairlie Nov 16 '17 at 13:45
-
1Create a common service to share the data and use router-outlet for the multi view – mohit uprim Nov 16 '17 at 15:45
-
2You need a service. Here's angular's tutorial: https://angular.io/tutorial/toh-pt4 – Notmfb Nov 16 '17 at 15:54
-
Hello, you can create a service with an EventEmitter and implement the function that get the dataset, when data are ready you emit the event. In the component where you want to display the resultSet subscribe the event, so when data will be ready the component will be notified. In the search panel you only need to call method which get the dataset. – IvanMoreno Nov 17 '17 at 07:42