source: Sources/frontend/src/app/add-answer.service.ts

Last change on this file was 8423429, checked in by AngelNasev <angel.nasev@…>, 15 months ago

Add backend and frontend projects

  • Property mode set to 100644
File size: 817 bytes
RevLine 
[8423429]1import { Injectable } from '@angular/core';
2import {HttpClient, HttpParams} from "@angular/common/http";
3import {Router} from "@angular/router";
4import {QuestionInterface} from "./QuestionInterface";
5import {AnswerInterface} from "./AnswerInterface";
6
7@Injectable({
8 providedIn: 'root'
9})
10export class AddAnswerService {
11
12 url = "http://localhost:8080/api/answers/add"
13 constructor(private http: HttpClient, private router: Router) {
14 }
15
16 add(content: string, username: string, questionId: number) {
17 const params = new HttpParams()
18 .append("content",content)
19 .append("username",username)
20 .append("questionId",questionId)
21 this.http.get<AnswerInterface>(this.url, {params:params})
22 .subscribe(resp => {
23 this.router.navigate(['/question-details/'+questionId]);
24 })
25 }
26}
Note: See TracBrowser for help on using the repository browser.