My Angular components include:
- Create-Articles: used for creating articles.
- List Articles: utilized for listing all articles.
The parent component is the Home Component.
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css']
})
export class HomeComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
<div class="container">
<div class="row">
<div class="col-md-4">
<articles-form></articles-form>
</div>
<div class="col-md-4">
<articles></articles>
</div>
</div>
</div>
I would like to automatically refresh the List Articles component every time a new article is created.
import { Component, OnInit } from '@angular/core';
import { ArticlesService } from '../../services/articles.service';
import { Article } from '../../models/article.model';
import { IArticles } from '../../interfaces/IArticles';
import { Observable } from 'rxjs';
@Component({
selector: 'articles',
templateUrl: './articles.component.html',
styleUrls: ['./articles.component.css'],
providers:[ArticlesService]
})
export class ArticlesComponent implements OnInit {
... // Code for fetching and displaying articles
}
<button class="btn btn-primary" (click)="fetchArticles()">
Reload Data
</button>
<div class="table table-responsive">
... // Table structure for displaying articles
</div>
import { Component, OnInit } from '@angular/core';
... // Import statements for ArticleForm related files
@Component({
selector: 'articles-form',
templateUrl: './articles-form.component.html',
styleUrls: ['./articles-form.component.css'],
providers:[ArticlesService]
})
export class ArticlesFormComponent implements OnInit {
... // Code for handling form submission to create an article
}
<div class="panel panel-primary">
... // Form structure for submitting new articles
</div>
To ensure real-time updates, I plan to refresh the List Articles component upon creating a new article.