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辅助器... 透视脚本!wepoker辅助器激活码,wepoker好友局透视,手段教程(竟然有挂)-哔哩哔哩小薇(...
透视规律!wepoker手机助... 透视规律!wepoker手机助手,hhpoker软件靠谱吗,办法教程(有挂细节)-哔哩哔哩1、用户打...
透视能赢!wepoker有透视... 透视能赢!wepoker有透视功能吗,wepoker如何设置透视,妙招教程(的确有挂)-哔哩哔哩1、...
透视安卓版!wepoker辅助... 透视安卓版!wepoker辅助器免费,we poker辅助器下载,学习教程(有挂方略)-哔哩哔哩1、...
透视规律!pokemmo免费脚... 透视规律!pokemmo免费脚本,智星德州可以透视吗,绝活教程(确实有挂)-哔哩哔哩进入游戏-大厅左...
透视智能ai!wepoker破... 透视智能ai!wepoker破解是真的还是假的,约局吧app有挂吗,方案教程(有挂秘诀)-哔哩哔哩1...
透视安装!hhpoker德州挂... 透视安装!hhpoker德州挂真的有吗,werplan怎么辅助,讲义教程(有挂工具)-哔哩哔哩1、进...
透视了解!aapoker破解侠... 透视了解!aapoker破解侠是真的吗,wepoker私人局俱乐部,技法教程(有挂工具)-哔哩哔哩a...
辅助透视!wepoker辅助器... 辅助透视!wepoker辅助器激活码,德州圈脚本,资料教程(有挂透视)-哔哩哔哩进入游戏-大厅左侧-...
透视辅助!wepoker手机版... 透视辅助!wepoker手机版辅助,约局吧辅助器,方案教程(有挂方法)-哔哩哔哩透视辅助!wepok...