จะทำซ้ำคำขอใน Angular ได้อย่างไร?

ฉันมีองค์ประกอบด้วยวิธี: load():

load() {
   this.simpleDictService
      .get(
         this.dictCode,
         this.pagination.from,
         this.pagination.to,
         this.showDeleted
      )
      .subscribe((response: IResponseDict) => { this.res = response; });
   }

วิธีการนี้จะถูกเรียกทุกครั้งที่ฉันพิมพ์ข้อความลงในช่องป้อนข้อมูล

เป็นผลให้ฉันได้รับข้อมูลตอบกลับจากเซิร์ฟเวอร์:

this.res = response; 

นอกจากนี้ยังมีปุ่มส่งออกไปยัง Excel เมื่อคลิกที่มัน ฉันต้องการทำซ้ำคำขอก่อนหน้าที่ส่งไปยังเซิร์ฟเวอร์พร้อมพารามิเตอร์เพิ่มเติม ฉันจะทำสิ่งนี้ใน Angular ได้อย่างไร

จริงๆ แล้ว ฉันสามารถเก็บ URL ก่อนหน้าไว้ในพื้นที่จัดเก็บแล้วแก้ไขได้


person OPV    schedule 10.09.2019    source แหล่งที่มา


คำตอบ (1)


คุณสามารถลองตอนนี้ได้ด้วยวิธีต่อไปนี้

    private subscriptionFileUpload;

    load() {
     if (this.subscriptionFileUpload) {
       this.subscriptionFileUpload.unsubscribe();
     }
     this.subscriptionFileUpload = this.simpleDictService
          .get(
            this.dictCode,
            this.pagination.from,
            this.pagination.to,
            this.showDeleted
          )
          .subscribe((response: IResponseDict) => { this.res = response; });
    }

วิธีการโหลดการโทรเมื่อคุณต้องการหรือคุณสามารถปล่อยเป็น .subscribe

person Shohel    schedule 10.09.2019