Skip to content

Commit

Permalink
added api service to submit fluid-form data
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjeetkumaritoutlook committed Dec 14, 2024
1 parent ef8a36b commit 6b9a99e
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/app/api.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { ApiService } from './api.service';

describe('ApiService', () => {
let service: ApiService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(ApiService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
19 changes: 19 additions & 0 deletions src/app/api.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
//Use Angular's HttpClient to manage your HTTP requests.

import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable({
providedIn: 'root'
})
//ng generate service api
export class ApiService {
private apiUrl = 'https://jsonplaceholder.typicode.com/posts'; // Sample public API

constructor(private http: HttpClient) { }
// Method to POST JSON data
postData(data: any): Observable<any> {
return this.http.post(this.apiUrl, data);
}
}
4 changes: 3 additions & 1 deletion src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { FluidParentComponent } from './fluid-parent/fluid-parent.component';
import { AppRoutingModule } from './app-routing.module';
import { LibraryComponentsComponent } from './library-components/library-components.component';
import { TestPagesComponent } from './test-pages/test-pages.component';
import { HttpClientModule } from '@angular/common/http';

@NgModule({
declarations: [
Expand All @@ -19,7 +20,8 @@ import { TestPagesComponent } from './test-pages/test-pages.component';
],
imports: [
BrowserModule,
AppRoutingModule
AppRoutingModule,
HttpClientModule
],
providers: [DatePipe],
bootstrap: [AppComponent],
Expand Down
12 changes: 11 additions & 1 deletion src/app/fluid-parent/fluid-parent.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ import {
querySelectorAllDeep,
querySelectorDeep,
} from 'query-selector-shadow-dom';
import { ApiService } from './../api.service';

@Component({
selector: 'app-fluid-parent',
Expand Down Expand Up @@ -213,8 +214,9 @@ _updateDebounceTime: number = 500; // Amount of time required to pass WITHOUT "f
},
};
templateValueKey: string;
response: any;

constructor(public datepipe: DatePipe) {}
constructor(public datepipe: DatePipe,private apiService: ApiService) {}
ngOnInit(): void {
console.log('on inittt');
this.loadFormsBindData('calling from onInit');
Expand Down Expand Up @@ -497,6 +499,14 @@ _updateDebounceTime: number = 500; // Amount of time required to pass WITHOUT "f

this.finalPolicyData.next(rawredactedValue);
console.log(events.detail.data);
//instead of api call in React, api call in angular
this.apiService.postData(rawredactedValue).subscribe({
next: (res) => {
console.log('Response:', res);
this.response = res;
},
error: (err) => console.error('Error:', err)
});
});
}
}

0 comments on commit 6b9a99e

Please sign in to comment.