Skip to content

Passing data into "router-outlet" child components #46283

@cesco69

Description

@cesco69

Which @angular/* package(s) are relevant/related to the feature request?

core

Description

I want a simple way to pass data into "router-outlet" child components

Proposed solution

@Component({
  selector : 'main',
  template : `<router-outlet [data]="data"></router-outlet>`
})
export class MainComponent {
    data = 'test';
}

Retrive the data into the routed component

import {ROUTER_DATA, Component, Inject } from '@angular/core';

@Component({
  selector: 'child',
  template: `{{data}}`
})
export class ChildComponent {
  constructor(@Inject(ROUTER_DATA) public data: any) { }
}

Alternatives considered

Nothing

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routerfeatureIssue that requests a new featurefeature: under considerationFeature request for which voting has completed and the request is now under consideration

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions