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模态框中实现数据的刷新和更新。

相关内容

热门资讯

一分钟揭秘“wepoker开挂... 无需打开直接搜索加微信客服(136704302)咨询了解wepoker开挂辅助辅助器目前(微信:13...
玩家必用“wpk到底有没有辅助... 您好:wpk到底有没有辅助挂的软件,软件加客服确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户...
交流学习经验“wepoker有... 无需打开直接搜索;操作使用教程:交流学习经验“wepoker有透视挂吗”开挂辅助脚本(透视)AA德州...
重大通报“wepoker软件辅... 无需打开直接搜索加微信客服(136704302)咨询了解wepoker软件辅助挂辅助器目前(微信:1...
技术分享“wepoker德州一... 无需打开直接搜索;操作使用教程:技术分享“wepoker德州一键透视购买”开挂辅助平台(透视)曝光教...
教程攻略“wepoker究竟有... 无需打开直接搜索;操作使用教程:教程攻略“wepoker究竟有没有挂”开挂辅助神器(透视)扑克教程1...
必备攻略“wePoKer有透视... 必备攻略“wePoKer有透视软件吗”开挂辅助工具(透视)教你攻略是一款可以让一直输的玩家,快速成为...
实测教程“微扑克辅助工具免费版... 实测教程“微扑克辅助工具免费版”开挂辅助安装(透视)2026教程是一款可以让一直输的玩家,快速成为一...
2026教程“wepoker透... 无需打开直接搜索;操作使用教程:2026教程“wepoker透视开挂挂教程”开挂辅助下载(透视)德州...
玩家必看教程“wpk有挂吗”开... 无需打开直接搜索;操作使用教程:玩家必看教程“wpk有挂吗”开挂辅助神器(透视)解密教程1、界面简单...