Hope you are well. I am quite new in typeScript and angular 4 and I have faced with an issue. I want to use one component in another component. The data will be accessible through Http with get method and comes in array of object in parent component and I want to use ngFor to repeat child component based on receiving data from parent component.
Following code is child component.ts
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-card',
templateUrl: './app-card.component.html',
styleUrls: ['./app-card.component.css']
})
export class AppCardComponent implements OnInit {
constructor() { }
ngOnInit() {
}
here is my child component.html
<mat-card class="pt-3">
<mat-card-header class="text-truncate pb-2">
<img mat-card-avatar src="http://material.angular.io/assets/img/examples/shiba1.jpg">
<mat-card-title class="mt-2">{{pro.name}}</mat-card-title>
</mat-card-header>
</mat-card>
Parent component.ts
import { Component, OnInit } from '@angular/core';
import { FeaturedService } from "../services/featured.service";
@Component({
selector: 'app-collection',
templateUrl: './collection.component.html',
styleUrls: ['./collection.component.css']
})
export class CollectionComponent implements OnInit {
cc;
constructor(private featured: FeaturedService) { }
ngOnInit() {
this.featured.getAll().subscribe(results => {
this.cc= results
});
}
}
and finally parent html
<div class="row">
<div class="col-12 text-center pt-4 mb-4">
<h3>Featured</h3>
<hr class="title-border" />
</div>
</div>
<div class="row">
<div *ngFor="let pro of cc" class="col-xl-6 p-md-1 p-lg-1 p-xl-2">
<app-card></app-card>
</div>
</div>
I do appreciate if you can help me to sort this issue out.
resultscoming from Http is correct ?