第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

POST請求后如何實時刷新數(shù)據(jù)?

POST請求后如何實時刷新數(shù)據(jù)?

胡子哥哥 2022-09-23 21:29:24
我有一個表格,將顯示數(shù)據(jù)。對于&request,一切正常,但只有在刷新頁面時,我才能在插入后看到值。POSTGETabc.service.tscreateExamCategory(options) {    return this.http.post<{ message: string }>(this.url + '/createExamCategory', options);}getExamCategory():Observable<any> {    return this.http.get<any>(this.url + '/getAllExamCategory');}abc.component.tsonSubmit() {    if(this.formdata.invalid) {      return;    }    this.adminCategory.createExamCategory(this.formdata.value).subscribe(reponse => {      console.log(reponse.message);    }); }ngOnInit() {  this.columnsToDisplay = ['id', 'examCategoryName', 'isActive', 'Action'];  this.adminCategory.getExamCategory().subscribe((reponse: any) => {      this.ExamCategoryData = reponse.examCategoryList;      this.dataSource = new MatTableDataSource(this.ExamCategoryData);      this.dataSource.paginator = this.paginator;  }, error => {       console.log(error);     }  );}這是我的代碼。我需要進行哪些必要的更改?
查看完整描述

3 回答

?
嗶嗶one

TA貢獻1854條經(jīng)驗 獲得超8個贊

您有兩種選擇:

  1. 將發(fā)送到 POST 請求的數(shù)據(jù)直接添加到表中。

  2. 在 POST 刷新表后獲取整個數(shù)據(jù)集。


查看完整回答
反對 回復(fù) 2022-09-23
?
慕少森

TA貢獻2019條經(jīng)驗 獲得超9個贊

有一個在線示例,說明如何刷新墊桌的視圖。Mat Table 本身并不知道數(shù)據(jù)源是否已更改,因此您基本上必須觸發(fā)更改檢測。下面的示例直接來自示例項目....


export interface Element {

  name: string;

  position: number;

  weight: number;

  symbol: string;

}


const ELEMENT_DATA: Element[] = [

  {position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'},

  {position: 2, name: 'Helium', weight: 4.0026, symbol: 'He'},

  {position: 3, name: 'Lithium', weight: 6.941, symbol: 'Li'},

  {position: 4, name: 'Beryllium', weight: 9.0122, symbol: 'Be'},

  {position: 5, name: 'Boron', weight: 10.811, symbol: 'B'},

  {position: 6, name: 'Carbon', weight: 12.0107, symbol: 'C'},

  {position: 7, name: 'Nitrogen', weight: 14.0067, symbol: 'N'}

];

只是一個正確定義的接口和示例數(shù)據(jù)集


// Displayed Columns, not important for the example

displayedColumns = ['position', 'name', 'weight', 'symbol'];

// We define the initial datasource

dataSource = new MatTableDataSource(ELEMENT_DATA);

那么他們在示例中所做的,基本上是刷新數(shù)組的引用...


addElement() {

// With the array function push() we make it possible for the Mat-Tables to refresh the view

    ELEMENT_DATA.push({position: 1, name: 'Hydrogen', weight: 1.0079, symbol: 'H'})

    this.dataSource = new MatTableDataSource(ELEMENT_DATA);

  }


查看完整回答
反對 回復(fù) 2022-09-23
?
Helenr

TA貢獻1780條經(jīng)驗 獲得超4個贊

將數(shù)據(jù)檢索代碼放入單獨的方法中,并在 POST 訂閱中重用它。


onSubmit() {

    if (this.formdata.invalid) {

        return;

    }

    this.adminCategory.createExamCategory(this.formdata.value).subscribe(reponse => {

        console.log(reponse.message);

        this.getData();

    });

}


ngOnInit() {

    this.columnsToDisplay = ['id', 'examCategoryName', 'isActive', 'Action'];

   this.getData();

}


private getData() {

    this.adminCategory.getExamCategory().subscribe(

        (reponse: any) => {

            this.ExamCategoryData = reponse.examCategoryList;

            this.dataSource = new MatTableDataSource(this.ExamCategoryData);

            this.dataSource.paginator = this.paginator;

        },

        error => {

            console.log(error);

        }

    );

}


查看完整回答
反對 回復(fù) 2022-09-23
  • 3 回答
  • 0 關(guān)注
  • 246 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號