// src/app/components/blog/blog.component.ts import { Component, OnInit } from '@angular/core'; import { CommonModule } from '@angular/common'; import { RouterLink } from '@angular/router'; import { BlogService } from '../services/blog.service'; @Component({ selector: 'app-blog', standalone: true, imports: [CommonModule, RouterLink], template: `

Latest Insights

Stay updated with our latest news and articles.

{{ post.title }}

{{ getShortContent(post.content) }}

Read More
` }) export class BlogComponent implements OnInit { blogPosts: any[] = []; constructor(private blogService: BlogService) {} ngOnInit() { const posts = this.blogService.getAllPosts(); // Convert the blogPosts object to an array this.blogPosts = Object.keys(posts).map(key => posts[key]); } // Function to get a short preview of the content getShortContent(content: string): string { const div = document.createElement('div'); div.innerHTML = content; const text = div.textContent || div.innerText || ''; return text.substring(0, 150) + '...'; } // Function to get post ID based on the title getPostId(title: string): string { const posts = this.blogService.getAllPosts(); for (const id in posts) { if (posts[id].title === title) { return id; } } return '1'; // Default to '1' if not found } }