Angular의 http 요청 모듈 사용법에 대한 간략한 설명
이 글에서는 Angular에서 http 요청 모듈을 사용하는 방법을 소개합니다. 도움이 필요한 친구들이 모두 참고할 수 있기를 바랍니다.
관련 권장 사항: "angular Tutorial"
먼저 모듈이 소개됩니다
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import {FormsModule} from '@angular/forms'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import {HttpClientModule,HttpClientJsonpModule} from '@angular/common/http' @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, AppRoutingModule, FormsModule, HttpClientModule, HttpClientJsonpModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
컴포넌트에 사용됨
import { Component, OnInit } from '@angular/core'; import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; import Qs from 'qs'; @Component({ selector: 'app-http', templateUrl: './http.component.html', styleUrls: ['./http.component.less'] }) export class HttpComponent implements OnInit { constructor(public http: HttpClient) { } ngOnInit(): void { this.getPostData(); //post this.getTestData(); //get this.getJsonpData() //jsonp } getPostData() { this.http.post('http://localhost:3000/api/info', { name: 'laney' }, { headers: new HttpHeaders({ 'Content-Type': 'application/json' }) }).subscribe((res) => { console.log(res); }) } getTestData() { var obj1 = { name: 'alice', age: '20' } var params = Qs.stringify(obj1); console.log(params) //第一种方式:字符串拼接 this.http.get('http://localhost:3000/api/school?' + params).subscribe((res) => { console.log(res); }) //第二种方式:HttpParams var oarma = new HttpParams({ fromString: params }); this.http.get('http://localhost:3000/api/school?', { params: oarma }).subscribe((res) => { console.log(res); }) } getJsonpData() { this.http.jsonp('http://localhost:3000/getscript', 'callback').subscribe((res) => { console.log(res); }) }
http 패키지
import { Injectable } from '@angular/core'; import {HttpClient,HttpHeaders,HttpParams} from '@angular/common/http'; import Qs from 'qs'; import { environment } from '../../environments/environment'; console.log(environment.baseURL); @Injectable({ providedIn: 'root' }) export class RxjsService { constructor(public http:HttpClient) { } postFun(url,data){ return this.http.post(environment.baseURL+url,data,{ headers:new HttpHeaders({ 'Content-Type':'application/json' }) }) } getFun(url,data){ var params = Qs.stringify(data); return this.http.get(environment.baseURL+url+'?'+params) } }
사용됨
import { Component, OnInit } from '@angular/core'; import {RxjsService} from '../../services/rxjs.service'; @Component({ selector: 'app-rxjs', templateUrl: './rxjs.component.html', styleUrls: ['./rxjs.component.less'] }) export class RxjsComponent implements OnInit { constructor(public rxjs:RxjsService) { } ngOnInit(): void { } getRXJS(){ this.rxjs.getFun('/api/school',{ name:'alice' }).subscribe((res)=>{ console.log(res); }) } postRXJS(){ this.rxjs.postFun('/api/info',{ name:'alice' }).subscribe((res)=>{ console.log(res); }) } }
더 보기 프로그래밍 관련 지식은 프로그래밍 비디오를 방문하세요! !
위 내용은 Angular의 http 요청 모듈 사용법에 대한 간략한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











이 글은 Angular에 대한 학습을 계속하고, Angular의 메타데이터와 데코레이터를 이해하고, 그 사용법을 간략하게 이해하는 데 도움이 되기를 바랍니다.

Angular.js는 동적 애플리케이션을 만들기 위해 자유롭게 액세스할 수 있는 JavaScript 플랫폼입니다. HTML 구문을 템플릿 언어로 확장하여 애플리케이션의 다양한 측면을 빠르고 명확하게 표현할 수 있습니다. Angular.js는 코드를 작성, 업데이트 및 테스트하는 데 도움이 되는 다양한 도구를 제공합니다. 또한 라우팅 및 양식 관리와 같은 많은 기능을 제공합니다. 이 가이드에서는 Ubuntu24에 Angular를 설치하는 방법에 대해 설명합니다. 먼저 Node.js를 설치해야 합니다. Node.js는 서버 측에서 JavaScript 코드를 실행할 수 있게 해주는 ChromeV8 엔진 기반의 JavaScript 실행 환경입니다. Ub에 있으려면

이 글은 Angular의 상태 관리자 NgRx에 대한 심층적인 이해를 제공하고 NgRx 사용 방법을 소개하는 글이 될 것입니다.

앵귤러 유니버셜(Angular Universal)을 아시나요? 웹사이트가 더 나은 SEO 지원을 제공하는 데 도움이 될 수 있습니다!

각도에서 모나코 편집기를 사용하는 방법은 무엇입니까? 다음 글은 최근 비즈니스에서 사용되는 Monaco-Editor의 활용 사례를 기록한 글입니다.

이 기사는 Angular의 실제 경험을 공유하고 ng-zorro와 결합된 angualr을 사용하여 백엔드 시스템을 빠르게 개발하는 방법을 배우게 될 것입니다. 모든 사람에게 도움이 되기를 바랍니다.

인터넷의 급속한 발전과 함께 프론트엔드 개발 기술도 지속적으로 개선되고 반복되고 있습니다. PHP와 Angular는 프런트엔드 개발에 널리 사용되는 두 가지 기술입니다. PHP는 양식 처리, 동적 페이지 생성, 액세스 권한 관리와 같은 작업을 처리할 수 있는 서버측 스크립팅 언어입니다. Angular는 단일 페이지 애플리케이션을 개발하고 구성 요소화된 웹 애플리케이션을 구축하는 데 사용할 수 있는 JavaScript 프레임워크입니다. 이 기사에서는 프론트엔드 개발에 PHP와 Angular를 사용하는 방법과 이들을 결합하는 방법을 소개합니다.

이 기사에서는 Angular의 독립 구성 요소, Angular에서 독립 구성 요소를 만드는 방법, 기존 모듈을 독립 구성 요소로 가져오는 방법을 안내합니다.
