import { HttpClient, HttpRequest, HttpResponse, HttpParams, HttpHeaders, } from '@angular/common/http'; import { NzMessageService, NzModalService, UploadFile } from 'ng-zorro-antd'; import { _HttpClient } from '@delon/theme'; import { Route, Router, ActivatedRoute, Params } from '@angular/router'; import { FormBuilder, FormGroup } from '@angular/forms'; import { Component, OnInit } from '@angular/core'; import {throttleTime} from "rxjs/operators"; import {debounceTime} from "rxjs-compat/operator/debounceTime"; @Component({ selector: 'zjcx', templateUrl: './zjcx.component.html', }) export class ZjcxComponent implements OnInit { pageIndex = 1; pageSize = 10; total = 0; data: any[] = []; loading = false; q = { pageIndex: 1, pageSize: 10, yhzh: '', zhmc: '', dfyhzh: '', dfzhmc: '', maxje: '' , minje: '', jysj: '', }; constructor( private http: _HttpClient, private httpClient: HttpClient, public msg: NzMessageService, private modalSrv: NzModalService, public router: Router, private fb: FormBuilder, ) { } ngOnInit() { this.msg.error("暂无数据"); } searchData(reset: boolean = false) { if (reset) { this.pageIndex = 1; } const yhzh = this.q.yhzh===null ? '':this.q.yhzh; const zhmc = this.q.zhmc===null ? '':this.q.zhmc; const dfyhzh = this.q.dfyhzh===null ? '':this.q.dfyhzh; const dfzhmc = this.q.dfzhmc===null ? '':this.q.dfzhmc; const minJe = this.q.minje===null ? '':this.q.minje; const maxJe = this.q.maxje===null ? '':this.q.maxje; const jysj = this.q.jysj===null ? '':this.q.jysj; const params = new HttpParams() .set('yhzh', yhzh) .set('zhmc', zhmc) .set('dfyhzh', dfyhzh) .set('dfzhmc', dfzhmc) .set('minJe', minJe) .set('maxJe', maxJe) .set('jysj', jysj) .set('pageIndex',''+this.pageIndex) .set('pageSize', ''+this.pageSize); this.loading=true; this.http .post('/download/zjfx/zjcx/getZjxx', params) .pipe(throttleTime(1000)) .subscribe((res: any) => { this.data = res.list; this.total = res.total; this.loading = false; },() => { this.loading = false; this.msg.error('任务查询失败,请重新再试!'); }); } }根据这个代码修改一下

时间: 2024-01-28 08:04:33 浏览: 32
根据你提供的代码,我看到你是在使用 `ng-zorro-antd` 的组件和 `_HttpClient` 来发送 HTTP 请求。为了解决查不到数据就会一直发送请求的问题,你可以在发送请求之前先判断一下当前是否已经有数据了,如果有,就不再发送请求。具体操作步骤如下: 1. 在组件类中添加一个变量来存储数据。 ```typescript data: any[] = []; ``` 2. 在 `searchData()` 方法中,先判断一下当前是否已经有数据了,如果有,就直接返回不再发送请求。 ```typescript searchData(reset: boolean = false) { if (reset) { this.pageIndex = 1; } if (this.data.length > 0) { return; } // 发送 HTTP 请求的代码 } ``` 通过这种方法,你的应用程序将在有数据的情况下不再发送 HTTP 请求,从而解决了查不到数据就会一直发送请求的问题。
相关问题

import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse;爆红

这段代码的问题可能是缺少对Java 11中HttpClient类的导入。请确保在代码中包含以下导入语句: ```java import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; ``` 如果你已经包含了这些导入语句,那么可能是因为你的IDE没有正确配置Java 11 SDK。请检查你的IDE设置,并确保它已正确配置Java 11 SDK。

请告诉我httpheaders在angular开发中是如何使用的

在Angular中,可以使用Angular提供的HttpClient模块来发送HTTP请求并处理HTTP响应。在发送HTTP请求时,可以使用HttpHeaders类来设置HTTP请求头。HttpHeaders类提供了一种简单的方式来设置HTTP请求头,如下所示: ``` import { HttpHeaders } from '@angular/common/http'; // 创建HTTP请求头 const httpOptions = { headers: new HttpHeaders({ 'Content-Type': 'application/json', 'Authorization': 'my-auth-token' }) }; // 发送HTTP POST请求 this.http.post(url, data, httpOptions).subscribe(response => { console.log(response); }); ``` 在上面的代码中,我们首先导入了HttpHeaders类,然后在创建HTTP请求头时使用它来设置HTTP请求头。在这个例子中,我们设置了Content-Type和Authorization两个HTTP请求头。最后,我们将httpOptions对象传递给post()方法,以便在发送HTTP POST请求时使用它。当HTTP响应返回时,我们使用subscribe()方法来处理响应。 需要注意的是,HttpHeaders类是不可变的,因此每次设置请求头时都需要创建新的HttpHeaders对象。如果需要添加或删除请求头,可以使用其set()、append()和delete()方法。例如,使用set()方法来设置Content-Type请求头: ``` const httpOptions = { headers: new HttpHeaders().set('Content-Type', 'application/json') }; ```

相关推荐

import { Component } from '@angular/core'; import { HttpClient } from '@angular/common/http'; interface Music { name: string; url: string; picurl: string; artistsname: string; } @Component({ selector: 'app-music-player', templateUrl: './music-player.component.html', styleUrls: ['./music-player.component.scss'] }) export class MusicPlayerComponent { currentSong!: string; musicList: Music[] = []; currentIndex!: number; constructor(private http: HttpClient) { this.getMusicList(); } play() { const audioElement: HTMLAudioElement = document.getElementById('audio') as HTMLAudioElement; audioElement.play(); } pause() { const audioElement: HTMLAudioElement = document.getElementById('audio') as HTMLAudioElement; audioElement.pause(); } next() { this.currentIndex++; if (this.currentIndex >= this.musicList.length) { this.currentIndex = 0; } this.currentSong = this.musicList[this.currentIndex].url; const audioElement: HTMLAudioElement = document.getElementById('audio') as HTMLAudioElement; audioElement.src = this.currentSong; audioElement.play(); } getMusicList() { this.http.get<any>('https://api.uomg.com/api/rand.music?sort=热歌榜&format=json&mid=2642575625').subscribe( res => { const musicName = res.data.name; // 获取音乐名称 this.musicList = [{ name: musicName, // 将音乐名称赋值给name url: res.data.url, picurl: res.data.picurl, artistsname: res.data.artistsname }]; this.currentIndex = 0; this.currentSong = this.musicList[this.currentIndex].url; const audioElement: HTMLAudioElement = document.getElementById('audio') as HTMLAudioElement; audioElement.src = this.currentSong; }, error => { console.log('获取音乐列表失败', error); } ); } }

最新推荐

recommend-type

HttpClient Post 二进制/字节流/byte[]实例代码

主要介绍了 HttpClient Post 二进制/字节流/byte[]实例代码的相关资料,需要的朋友可以参考下
recommend-type

Android程序报错程序包org.apache.http不存在问题的解决方法

主要介绍了Android程序报错"程序包org.apache.http不存在——Android 6.0已经不支持HttpClient" 问题的解决方法,感兴趣的小伙伴们可以参考一下
recommend-type

C#实现HTTP下载文件的方法

主要介绍了C#实现HTTP下载文件的方法,包括了HTTP通信的创建、本地文件的写入等,非常具有实用价值,需要的朋友可以参考下
recommend-type

C#使用Http Post方式传递Json数据字符串调用Web Service

主要为大家详细介绍了C#使用Http Post方式传递Json数据字符串调用Web Service,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
recommend-type

JAVA利用HttpClient进行HTTPS接口调用的方法

本篇文章主要介绍了JAVA利用HttpClient进行HTTPS接口调用的方法,具有一定的参考价值,有兴趣的可以了解一下
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

用 Python 画一个可以动的爱心

好的,我可以帮助您使用Python来绘制一个动态的爱心。您可以使用turtle库来实现。以下是实现代码: ```python import turtle import math # 设置画布和画笔 canvas = turtle.Screen() canvas.bgcolor("black") pencil = turtle.Turtle() pencil.speed(0) pencil.color("red", "pink") pencil.pensize(3) # 定义爱心函数 def draw_love(heart_size, x_offset=0, y_offset=0):
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。