【问题标题】:ionic angular view is not getting refreshed with new data离子角度视图没有用新数据刷新
【发布时间】:2020-01-22 20:37:06
【问题描述】:

一段时间后我得到了一些数据,我想将这些数据合并/替换为之前收到的数据,但它不起作用。 这是我如何替换原始结果数据。

result: Observable<SmsResponse>;
 constructor() {
    this.result = Plugins.SmsaccessPlugin.getAllSms({ value: "inbox"});
  }

  @HostListener("document:myCustomEvent", ["$event"])
  on(event: any) {
    var msg:Observable<SmsResponse> = of(event);
    this.result=msg;//<--- here, but template not showing this new data
  }

在 html 模板上,它与异步管道 (result | async) 一起使用。 (或者有什么方法可以从电容中获取数据?)

【问题讨论】:

    标签: angular typescript ionic-framework ionic4 capacitor


    【解决方案1】:

    尝试使用NgZone 强制进行角度变化检测

    constructor(private zone: NgZone) {
       this.result = Plugins.SmsaccessPlugin.getAllSms({ value: "inbox"});
    });
    
    this.zone.run(() => {
      ...
      this.result = msg;
      ...
    });
    

    【讨论】:

      【解决方案2】:

      向父 dom 元素添加 *ngIf="result" 然后{{结果|异步}}

      顺便说一句。你的 customEvent 真的触发了吗??

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-11-16
        • 2015-06-26
        • 2016-10-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多