Professional Documents
Culture Documents
Use @output With of "Angular 4.0": Stack Overflow
Use @output With of "Angular 4.0": Stack Overflow
1. Products
1.
Juan Choque
1
, 1 reputation
2. 1
3.
4.
5.
6.
1. Home
2.
1. PUBLIC
2. Stack Overflow
3. Tags
4. Users
5. Jobs
3.
1. TEAMS
What’s this?
2.
First 10 Free
<app-child1 (onVoted)="onVoted($event)"></app-child1>
But using a router will fail
<router-outlet (onVoted)="onVoted($event)"></router-outlet>
I want to receive a value from a component displayed on the "router-outlet".
angular angular-components
shareedit
edited May 5 '17 at 5:28
asked May 5 '17 at 4:29
くにあつ
14099 bronze badges
• 3
you cannot create @Output variable to angular packages. What you mean by this line "I want to receive a
value from a component displayed on the router." – Aravind May 5 '17 at 4:30
• 1
Use a service angular.io/docs/ts/latest/cookbook/… – eko May 5 '17 at 4:43
• 1
>>Mr.Aravind 「you cannot create @Output variable to angular packages.」
Why??? toparent.herokuapp.com Press the second displayed button.title is changed.@Output is
working normally.But only selectors.I hope you will be able to provide the information. – くにあつ May 5
'17 at 5:16
• 1
Possible duplicate of Angular 2 output from router-outlet – AJT82 May 6 '17 at 9:05
add a comment
1 Answer
active oldest votes
1
You can define an @Output event emitter in the component being rendered at router-outlet.
define router outlet as follows.
*.html
<router-outlet (activate)="onActivate($event)"></router-outlet>
In your component you can do as so.
onActivate(elementRef) {
elementRef.<the @Output eventEmitter>.subscribe(event => {
console.log(event);
});
}
This way you can send the events to the component which is rendering router-outlet. This
works because @Output event emitters are event streams and you can subscribe to those
events.
https://angular.io/api/router/RouterOutlet
shareedit
answered Jul 11 '18 at 18:31
mruanova
2,52422 gold badges1818 silver badges3838 bronze badges
add a comment
Your Answer
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
•
• Links
• Images
• Styling/Headers
• Lists
• Blockquotes
• Code
• HTML
• advanced help »
Post Your Answer
Not the answer you're looking for? Browse other questions tagged angular angular-
•
DevOps Engineer
Cardinal Financial Company, LPNo office location
REMOTE
dockeramazon-web-services
•
Senior Android/Kotlin Developer (Remote)
X-TeamNo office location
REMOTE
androidionic-framework
•
React Native Engineer
Codelitt, Inc.No office location
$45K - $80KREMOTE
androidios
Linked
48
Angular 2 output from router-outlet
Related
8
Angular 2 how to pass variable from parent component to router outlet
494
What is the equivalent of ngShow and ngHide in Angular 2+?
5
angular 2 update app component from router outlet component
48
Angular 2 output from router-outlet
3
angular2 target specific router-outlet
0
Router Outlets Angular 2
0
Angular 4 router-outlet content
0
Angular router outlet automatically activating
0
How to show ngx-loading animation only to router-outlet?
0
Angular component outside of router outlet
Question feed
https://stack
STACK OVERFLOW
• Questions
• Jobs
• Developer Jobs Directory
• Salary Calculator
• Help
• Mobile
• Disable Responsiveness
PRODUCTS
• Teams
• Talent
• Advertising
• Enterprise
COMPANY
• About
• Press
• Work Here
• Legal
• Privacy Policy
• Contact Us
STACK EXCHANGE
NETWORK
• Technology
• Life / Arts
• Culture / Recreation
• Science
• Other
• Blog
• Facebook
• Twitter
• LinkedIn
site design / logo © 2019 Stack Exchange Inc; user contributions licensed under cc by-sa 4.0 with attribution
required. rev 2019.10.18.35213