Angular 7, I have a component which responds to a route like this
export class MyComponent implements OnInit {
ngOnInit() {
this.route.paramMap.pipe(
switchMap((params: ParamMap) => {
return this.myService.get(+params.get('id'));
})
)
.subscribe( ...
Now in another component template, I want to invoke this component directly in the template, how do I do that?
<app-my></app-my>
How do I provide the routing parameter id
?
Just use/add @Input
and use standard property binding.
MyComponent.ts
export class MyComponent implements OnInit {
@Input()
id: string;
ngOnInit() {
if(!this.id)
{
this.route.paramMap.pipe(
switchMap((params: ParamMap) => {
return this.myService.get(+params.get('id'));
})
)
.subscribe( ...
root-component.ts
<app-my [id]="'some value'"></app-my>
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments