Skip to content

Commit

Permalink
chore: add http
Browse files Browse the repository at this point in the history
  • Loading branch information
dtopalov committed Sep 20, 2024
1 parent 1426f37 commit 02cc9b6
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
3 changes: 2 additions & 1 deletion examples-standalone/coffee-warehouse/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ import { SettingsService } from './settings.service';
IconsModule,
WindowModule,
IndicatorsModule,
NavigationModule
NavigationModule,
HttpClientModule
],
providers: [
{ provide: MessageService, useClass: CustomMessagesService },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { SettingsService } from '../../settings.service';
import { groupBy } from '@progress/kendo-data-query';
import { SVGIcon, arrowRotateCcwIcon, fontFamilyIcon, imageResizeIcon, pauseSmIcon, underlineIcon } from '@progress/kendo-svg-icons';
import { contrastIcon, darkModeIcon, dyslexiaFontIcon, microphoneIcon } from './svg-icons';
import { Subscription } from 'rxjs';
import { map, Subscription } from 'rxjs';
import { HttpService } from '../../http.service';

@Component({
selector: 'app-settings-list-component',
Expand Down Expand Up @@ -55,7 +56,9 @@ export class SettingsListComponent {
public resizeIcon: SVGIcon = imageResizeIcon;
public dyslexiaFontIcon: SVGIcon = dyslexiaFontIcon;

constructor(private settingsService: SettingsService) { }
constructor(
private settingsService: SettingsService,
private httpService: HttpService) { }

public getSetting(prop: string): string {
return this.settingsService.settings[prop];
Expand All @@ -67,6 +70,17 @@ export class SettingsListComponent {

public onValueChange(value: string) {
console.log(`combo value changed, new value: `, value);
// get settings after API call
// call settingChange with the respective settings for the combobox value

// sample usage
this.subs.add(this.httpService.get('https://jsonplaceholder.typicode.com/todos/1')
.subscribe(r => console.log('from API', r)));

this.subs.add(this.httpService.post('https://jsonplaceholder.typicode.com/posts', {
title: value,
body: 'body',
userId: 1,
}).subscribe(r => console.log('from API', r)));
}
}
17 changes: 17 additions & 0 deletions examples-standalone/coffee-warehouse/src/app/http.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';

@Injectable({providedIn: 'root'})
export class HttpService {
constructor(private http: HttpClient) { }

public get(url: string): Observable<any> {
return this.http.get(url);
}

public post(url: string, payload: any): Observable<any> {
return this.http.post(url, payload);
}
}

0 comments on commit 02cc9b6

Please sign in to comment.