New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FR: Get ComponentRef using component instance #23301

avber opened this Issue Apr 11, 2018 · 1 comment


None yet
3 participants
Copy link

avber commented Apr 11, 2018

I'm submitting a...

[x ] Feature request

Expected behavior

var ref = SomeAngularBuiltinService.getComponentRef(componentInstance);

//some code to use Angular services

This should also work with lazy loaded modules.

What is the motivation / use case for changing the behavior?

It will be possible to write specialized decorators that require access to Angular built in services.

Here is an example:

export class TasksComponent implements OnInit {

@fromRoute('id', (o: TasksComponent) => {
projectId: string;


It's more concise than

export class TasksComponent implements OnInit {
projectId = '';

constructor(private route: ActivatedRoute) {

ngOnInit() {

this.projectId$ = this.route.paramMap
  .switchMap((params: ParamMap) =>

  this.projectId$.subscribe(val => {
       this.projectId  = val;


Currently I have to patch component factories and router config loader in order to achieve it.

@ngbot ngbot bot added this to the needsTriage milestone Apr 12, 2018

@ngbot ngbot bot modified the milestones: needsTriage, Backlog Apr 24, 2018


This comment has been minimized.

Copy link

avber commented May 5, 2018

Ideally there should be a similar feature for services:

var injector = SomeAngularBuiltinService.getServiceInjector(serviceInstance);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment