I am trying to pass a map, which come from an api, from parent to child component, in angular 7.
parent.ts:
export class AppComponent {
title = 'taurs-frontend';
categories: any;
isLoggedIn = false;
ngOnInit(){
this.roomDataService.getData(`${environment.api_url}/api/Categories`)
.subscribe(categories => {
this.categories=categories
});
}
parent.html:
<app-room-card [categories]="categories"></app-room-card>
child.ts:
@Component({
selector: 'app-room-card',
templateUrl: './room-card.component.html',
styleUrls: ['./room-card.component.css']
})
export class RoomCardComponent implements OnInit {
@Input('categories') catname: any;
ngOnInit() {
console.log('aaa'+ this.catname);
}
// ..
}
When I try to log the variable catname, it is undefined. If I try to import variable title from the parent, everything works properly. How can I pass categories to the child, filling it with the values from the API call?