Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { Injectable } from '@angular/core';
- import {HttpClient} from "@angular/common/http";
- import {Post} from "./_models/post";
- @Injectable({
- providedIn: 'root'
- })
- export class PostService {
- http: HttpClient
- backendUrl: string = 'https://localhost:7015';
- posts: Post[]
- id: string
- constructor(http: HttpClient, id:string) {
- this.http=http
- this.posts=[];
- this.id=id;
- }
- getPosts(): void {
- this.http
- .get<Post[]>('https://localhost:7015/api/PostsApi/GetPostsofSubject/' + this.id)
- .subscribe(resp => {
- resp.map(x => {
- let p = new Post()
- p.subjectCode = x.subjectCode
- p.id = x.id
- p.content = x.content
- p.editCount = x.editCount
- p.lastEdited = x.lastEdited
- p.siteUserId = x.siteUserId
- p.timestamp = x.timestamp
- this.posts.push(p)
- })
- console.log(this.posts)
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement