天天看點

關于Angular使用http發送請求後的響應處理

import { Component, OnInit } from '@angular/core';
import { FormControl } from '@angular/forms';
import { HttpClient } from '@angular/common/http';

const ENDPOINT = "http://localhost:3000/echo?data=";

@Component({
  selector: 'jerryform',
  template: `
    <input type="text" [formControl]="favoriteColorControl">
  `
})
export class ReactFormComponent implements OnInit  {

  constructor(private http:HttpClient){
  }
  ngOnInit(): void {
    this.favoriteColorControl.valueChanges.subscribe(
      (value) =>{
        console.log('new value: ' + value);
        this.http.get('http://localhost:3000/angular/' + value).subscribe((response)=>console.log('response from http: ' + response),
        (error)=>console.log('error: ' + error));
      }
    )
  }
  favoriteColorControl = new FormControl('');
}
      
關于Angular使用http發送請求後的響應處理
關于Angular使用http發送請求後的響應處理
關于Angular使用http發送請求後的響應處理
關于Angular使用http發送請求後的響應處理

繼續閱讀