Skip to content

Instantly share code, notes, and snippets.

@desoga10
Created June 23, 2023 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save desoga10/a22be89dd5e7371a0a902b300dbf201f to your computer and use it in GitHub Desktop.
Save desoga10/a22be89dd5e7371a0a902b300dbf201f to your computer and use it in GitHub Desktop.
import { Component } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DataService } from './service/data.service';
interface Post {
userId: number;
id: number;
title: string;
body: string;
}
@Component({
selector: 'app-root',
standalone: true,
imports: [CommonModule],
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = 'ng-client';
posts: Post[] = [];
errorMessage!: string;
constructor(private data_service: DataService) {}
ngOnInit() {
this.data_service.getAllPosts().subscribe({
next: (posts) => {
this.posts = posts;
console.log(this.posts);
},
error: (error) => {
this.errorMessage = error;
},
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment