I'm working on my first angular project and my home component html looks like below
<div class="container">
<div>
<div class="col-md-4">
<h1 id="tableLabel">Latest</h1>
<news-item [section]="Latest"></news-item>
</div>
<div class="col-md-4">
<h1 id="tableLabel">STEM Stuff</h1>
<news-item [section]="STEM"></news-item>
</div>
</div>
</div>
and the ts for news-item is as below
import { Component, Inject, Input } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Component({
selector: 'news-item',
templateUrl: './news-item.component.html',
})
export class NewsItemComponent {
public newsitems: NewsItem[];
@Input() section: string;
constructor(http: HttpClient, @Inject('BASE_URL') baseUrl: string) {
http.get<NewsItem[]>(baseUrl + 'newsitems/GetNewsItemsBySection/' + this.section).subscribe(result => {
this.newsitems = result;
}, error => console.error(error));
}
}
I'm getting this.section as undefined within the constructor. What am I missing ?
sectionas@Input? are you passing some information from<news-item>to the controller? At first instance<news-item>looks like for rendering purpose only.