4Manuals

  • PDF Cloud HOME

如何在角度8上检索表单POST响应 Download

    如何将动态模板引用Click事件绑定到跨度? Jspdf在最新的Chrome版本中保存时间过长(79.0.3945.88) Golang服务器无法从远程REST API获取所有JSON 使用SODA API Python从数据集中导入所有行 IIS 10中的网址重写 我正在一个项目中,我以古吉拉特语插入数据,但是当我通过数据表检索数据时,它会显示编码数据 Angular 7:类型为radio的复选框,使用ngModel还是change-function? 为什么Qr代码没有使用HTML元素下载 如何使用ngx-pagination显示特定页面中存在的记录数 清单提取失败,返回状态404

在html表单上进行POST调用后,如何检索服务器的服务器响应?

<form action="http://localhost:8080/upload" method="POST">
<label for="file">Choose File</label>
    <input type="file"
        id="file"
        enctype="multipart/form-data">
    <div *ngIf=badName>
        <small id="emailHelp" class="form-text text-muted">Wrong file format. Only accepted format: csv.</small>
    </div>
    <button type="submit" value="Submit" class="btn btn-primary">Submit</button>
</form>

1 个答案:

答案 0 :(得分:2)

作为一种好的做法,请考虑使用将数据发送到服务器并从服务器获得响应的服务。

来自the Angular docs的示例:

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

import { Observable, of } from 'rxjs';
import { catchError, map, tap } from 'rxjs/operators';

import { Hero } from './hero';
import { MessageService } from './message.service';


@Injectable({ providedIn: 'root' })
export class HeroService {
    private heroesUrl = 'api/heroes';  // URL to web api

    httpOptions = {
        headers: new HttpHeaders({ 'Content-Type': 'application/json' })
    };

    constructor(private http: HttpClient) { }

    /** POST: add a new hero to the server */
    addHero (hero: Hero): Observable<Hero> {
        return this.http.post<Hero>(this.heroesUrl, hero, this.httpOptions).pipe(
            tap((newHero: Hero) => this.log(`added hero w/ id=${newHero.id}`)),
            catchError(this.handleError<Hero>('addHero'))
        );
    }
}

yourcomponent.ts:

constructor(private heroService:  HeroService ) {  }

create(){
    this.heroService.addHero( yourObject ).subscribe(resp => {
        console.log(resp)
    }) 
}



Similar searches
    如何在TCPDF中添加Jameel Noori Nastaleeq字体? Yii2如何添加带有关系表字段的过滤器 无法在其他功能中使用功能 如何在.NET Core中管理项目的程序集? 如何显示所有信息的动物?