This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
exercise.service.ts 902 B
Newer Older
Michael Breu's avatar
Michael Breu committed
import { Injectable } from '@angular/core';
import { HttpClient, HttpParams, HttpHeaders } from '@angular/common/http';
Michael Breu's avatar
Michael Breu committed
import { Observable } from 'rxjs';

import { SERVER_API_URL } from 'app/app.constants';

@Injectable({ providedIn: 'root' })
export class ExerciseService {
    public resourceUrl = SERVER_API_URL + 'api/exerciseFile/';
Michael Breu's avatar
Michael Breu committed

    constructor(private http: HttpClient) {}

    public loadExerciseFile(exerciseId: string, filePath: string): Observable<string> {
        const headers = new HttpHeaders(); // .set('Content-Type', 'text/plain; charset=utf-8');
Michael Breu's avatar
Michael Breu committed
        const options: HttpParams = new HttpParams();
        options.append('filePath', filePath);

        return this.http.get<string>(this.resourceUrl + exerciseId, {
            headers,
             params: new HttpParams().set('filePath', filePath),
             responseType: 'text' as 'json'
             });