2

I am trying to pass inputs/outputs to the lazy loaded component, but I'm not sure how I can do that.

If it's not lazy loaded, I know that I can do that like this.

test.ts

testdata: string;

ngOnInit(){
  this.testdata = "TEST";
}

test.html

<test-component [data]="testdata"></test-component>

testcomponent.ts

@Input() data: string;

But what if testcomponent is lazy loaded and I have something like this?

testcomponent is loaded, when user goes on specific path.

test.html

<router-outlet></router-outlet>
1
  • Thank you guys. Its a shame, i completely missed that i can use services. Commented Oct 14, 2016 at 7:24

2 Answers 2

1

You can use one of the following:

  1. use a query string to pass the data to lazy loaded components; or

  2. use a shared service to pass the data from main component and store the data in a variable and when the lazy component is loaded just read the value of this variable in onInit function

Sign up to request clarification or add additional context in comments.

1 Comment

Why do lazy-loaded components do not pass data to @Input() variables?
0

There is no way to use binding with components added by the router or ViewContainerRef.createComponent.

Use a shared service to communicate with components that are not direct parent-child like explained in https://angular.io/docs/ts/latest/cookbook/component-communication.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.