Advertisement
kklevi

postservice

May 29th, 2023 (edited)
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import { Injectable } from '@angular/core';
  2. import {HttpClient} from "@angular/common/http";
  3. import {Post} from "./_models/post";
  4.  
  5. @Injectable({
  6.   providedIn: 'root'
  7. })
  8. export class PostService {
  9.   http: HttpClient
  10.   backendUrl: string = 'https://localhost:7015';
  11.   posts: Post[]
  12.   id: string
  13.   constructor(http: HttpClient, id:string) {
  14.     this.http=http
  15.     this.posts=[];
  16.     this.id=id;
  17.   }
  18.  
  19.   getPosts(): void {
  20.     this.http
  21.       .get<Post[]>('https://localhost:7015/api/PostsApi/GetPostsofSubject/' + this.id)
  22.       .subscribe(resp => {
  23.         resp.map(x => {
  24.           let p = new Post()
  25.           p.subjectCode = x.subjectCode
  26.           p.id = x.id
  27.           p.content = x.content
  28.           p.editCount = x.editCount
  29.           p.lastEdited = x.lastEdited
  30.           p.siteUserId = x.siteUserId
  31.           p.timestamp = x.timestamp
  32.  
  33.           this.posts.push(p)
  34.         })
  35.         console.log(this.posts)
  36.       })
  37.   }
  38.  
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement