Angular模态框中的数据在数据更改后未刷新。
创始人
2024-10-28 15:31:43
0

问题描述: 在Angular模态框中,当数据发生更改后,模态框中的数据未刷新,导致显示的数据和实际数据不一致。

解决方法:

  1. 在模态框组件中,通过订阅数据变化事件来刷新数据。
import { Component, Input, OnChanges, SimpleChanges } from '@angular/core';

@Component({
  selector: 'app-modal',
  template: `
    
  `,
})
export class ModalComponent implements OnChanges {
  @Input() data: string;

  ngOnChanges(changes: SimpleChanges) {
    if (changes.data) {
      this.data = changes.data.currentValue;
    }
  }
}
  1. 在调用模态框的组件中,使用ngOnInit钩子函数来监听数据的变化并更新模态框的数据。
import { Component, OnInit } from '@angular/core';
import { NgbModal } from '@ng-bootstrap/ng-bootstrap';

@Component({
  selector: 'app-parent-component',
  template: `
    
  `,
})
export class ParentComponent implements OnInit {
  data: string;

  constructor(private modalService: NgbModal) {}

  ngOnInit() {
    // 监听数据变化并更新模态框的数据
    this.data = 'Initial data';
  }

  openModal() {
    const modalRef = this.modalService.open(ModalComponent);
    modalRef.componentInstance.data = this.data;
  }
}

通过以上两个步骤,即可在Angular模态框中实现数据的刷新和更新。

相关内容

热门资讯

辅助开挂!微乐山西小程序破解器... 辅助开挂!微乐山西小程序破解器,hhpoker德州机器人(透视)开挂辅助插件(真的有挂);微乐山西小...
开挂辅助脚本"德普之... 您好:这款德普之星透视辅助软件下载游戏是可以开挂的,确实是有挂的,很多玩家在这款德普之星透视辅助软件...
辅助开挂!wepoker辅助,... 辅助开挂!wepoker辅助,智星菠萝透视(透视)开挂辅助工具(有挂工具);1、点击下载安装,wep...
开挂辅助工具"hhp... hhpoker软件可以玩吗 无需打开直接搜索微信:136704302本司针对手游进行,选择我们的四大...
辅助开挂!微乐广西麻辣,pok... 辅助开挂!微乐广西麻辣,poker world辅助(透视)开挂辅助插件(有挂方针);微乐广西麻辣中的...
开挂辅助神器"clo... 开挂辅助神器"cloudpoker辅助"开挂(透视)辅助插件(有挂方式);无需打开直接搜索打开薇:1...
开挂辅助脚本"wep... 开挂辅助脚本"wepoker私人局俱乐部"开挂(透视)辅助神器(有挂方法);无需打开直接搜索薇:13...
开挂辅助!微友助手破解版,约局... 开挂辅助!微友助手破解版,约局吧是否有挂(透视)开挂辅助神器(竟然有挂);微友助手破解版中的10万兆...
开挂辅助平台"wep... 开挂辅助平台"wepoker私人局透视教程"开挂(透视)辅助插件(确实有挂);无需打开直接搜索薇:1...
辅助开挂!九九联盟点控吗辅助器... 辅助开挂!九九联盟点控吗辅助器,wepoker科技辅助器(透视)开挂辅助下载(有挂秘笈);九九联盟点...