Search
 
SCRIPT & CODE EXAMPLE
 

TYPESCRIPT

angular add httpclient

import { HttpClientModule } from '@angular/common/http';
// if you use services just import this
import { HttpClient } from '@angular/common/http';
//................................................
@NgModule({
  imports: [
    BrowserModule,
    // import HttpClientModule after BrowserModule.
    HttpClientModule,
  ],
  
  // in you component.ts
  readonly ROOT_URL = "https://jsonplaceholder.typicode.com";
  
 constructor( private http: HttpClient) { }
  
  this.http.get(this.ROOT_URL + '/posts')
    .subscribe((response)=>{
      alert(JSON.stringify(response));
    });

// send information

this.http.post(this.ROOT_URL + '/posts',
              { id: 1, title: "sami"} )
    .subscribe((response)=>{
      alert(JSON.stringify(response));
    });

// update

this.http.put(this.ROOT_URL + '/posts')
    .subscribe((response)=>{
      alert(JSON.stringify(response));
    });

// fetch

// delete
  
Comment

PREVIOUS NEXT
Code Example
Typescript :: [ERROR] @ionic/app-scripts is required for this command to work properly. 
Typescript :: typescript canvas 
Typescript :: how to select last 2 elements in a string python 
Typescript :: deno web server 
Typescript :: google sheets remove last character 
Typescript :: mui styles hover mouse pointer 
Typescript :: redux toolkit typescript install 
Typescript :: open ports on RPI 
Typescript :: python multiply digits of a number 
Typescript :: golang terminal prompts disabled 
Typescript :: serenity.-is add column picker button 
Typescript :: add google font in tailwind css 
Typescript :: typescript get the mime type from base64 string 
Typescript :: remove duplicate break line from string in typescript 
Typescript :: plot 3d points in python 
Typescript :: adonis auth register 
Typescript :: ion2 calendar locale 
Typescript :: how many terrorists do not conform to the gender binary 
Typescript :: your account has reached its concurrent builds limit 
Typescript :: headphone disconnects in ubuntu 
Typescript :: move items from one log to another typescript 
Typescript :: wordpress get post attachments url 
Typescript :: get tweets from user tweepy 
Typescript :: how to configure email alerts in grafana container 
Typescript :: check if document exists firestore flutter 
Typescript :: what is test management review 
Typescript :: online meeting platforms 
Typescript :: angular change element style on click 
Typescript :: python convert two lists with duplicates to dictiona 
Typescript :: drop table if exists redshift 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =