Skip to content

Instantly share code, notes, and snippets.

@felixlindemann
Created November 21, 2021 11:59
Show Gist options
  • Save felixlindemann/4a43d904bf873e093728f9f27f589c82 to your computer and use it in GitHub Desktop.
Save felixlindemann/4a43d904bf873e093728f9f27f589c82 to your computer and use it in GitHub Desktop.
Blog in Angular - Posts-Service
@Injectable({
providedIn: 'root'
})
export class PostsService {
private _posts: blogPost[] = [];
get Posts(): blogPost[] {
return this._posts;
}
set Posts(value: blogPost[]) {
this._posts = value;
}
constructor() {
if (this.Posts === null || this.Posts.length > 0) this.Posts = [];
this.Posts = posts
.map(post => new post())
.sort((a, b) => a.postDateTime > b.postDateTime ? -1 : 1)
;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment