24
loading...
This website collects cookies to deliver better user experience
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { HttpClientModule } from '@angular/common/http';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Ng generate service DemoService
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class DemoServiceService {
constructor() { }
}
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
@Injectable({
providedIn: 'root'
})
export class DemoServiceService {
constructor( private httpClient: HttpClient ) { }
}
export const environment = {
production: true
};
// This file can be replaced during build by using the `fileReplacements` array.
// `ng build --prod` replaces `environment.ts` with `environment.prod.ts`.
// The list of file replacements can be found in `angular.json`.
export const environment = {
production: false,
API_URL: 'http://192.168.0.88:8098/api'
};
/*
* For easier debugging in development mode, you can import the following file
* to ignore zone related error stack frames such as `zone.run`, `zoneDelegate.invokeTask`.
*
* This import should be commented out in production mode because it will have a negative impact
* on performance if an error is thrown.
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
URL = environment.APP_URL; // endpoint URL
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class DemoServiceService {
URL = environment.API_URL; // endpoint URL
constructor( private httpClient: HttpClient ) { }
}
ng g class Employee
export class Employee {
Empid: number;
Empname: string;
Empaddress: string;
Mobile: number;
Salary: number;
}
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse, HttpHeaders } from '@angular/common/http';
import { Employee } from './employee';
import { Observable } from 'rxjs';
import { environment } from 'src/environments/environment';
@Injectable({
providedIn: 'root'
})
export class DemoServiceService {
URL = environment.API_URL; // endpoint URL
httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
})
}
constructor( private http: HttpClient ) { }
getAllEmployee(): Observable<any> {
return this.http.get(`${this.URL}`);
}
create(employee: any): Observable<employee> {
return this.http.post<employee>(`${this.URL}` , employee, this.httpOptions);
}
deleteEmployee(id: number): Observable<any> {
return this.http.delete(`${this.URL}/${id}`, { responseType: 'text' });
}
update(id: string, employee: any): Observable<employee> {
return this.http.put<employee>(`${this.URL}` + id, employee, this.httpOptions);
}
find(id: string): Observable<employee> {
return this.http.get<employee>(`${this.URL}` + id);
}
}
</employee></employee></employee></employee></any></employee></employee></any>