Angular amTimeAgo无法刷新

时间:2018-07-16 15:50:02

标签: angular angular2-moment

每当我调用函数“ resetDate”时,我都试图刷新amTimeAgo,但是它不起作用。它正在控制台中记录正确的新时间,但是该时间不会在页面上刷新。

    import { NgModule, Component, OnInit } from '@angular/core';
    import {BrowserModule} from '@angular/platform-browser';
    import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
    import { MomentModule } from 'angular2-moment';
    import { HttpClient } from '@angular/common/http';

    @Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})

    export class AppComponent {
       getSystemsStatus () {
         this.httpClient.get<serverResponse>('http://127.0.0.1:5000/systemsStatus').subscribe(data => {
        if (JSON.stringify(this.systemStatusText) === JSON.stringify(data.systemStatusText)) {

        }
        else {
          this.systemStatus=data.systemStatus;
          this.systemStatusText=data.systemStatusText;
          let callTimeagoComponent = new TimeagoComponent();
          callTimeagoComponent.resetDate();
        }
        });
    };
  }
}

    @Component({
          selector: 'lastUpdated',
          template: '<div id="time1"><time>Last updated: {{myDate | amTimeAgo}}</time>'
        })

        export class TimeagoComponent{
          myDate = new Date();
          resetDate() {
            this.myDate = new Date();
          }
        }


    @NgModule({
      imports: [
        BrowserModule,
        MomentModule
      ],
      declarations: [ TimeagoComponent ],
      bootstrap: [ TimeagoComponent ]
    })
    class TimeagoModule {}

    platformBrowserDynamic().bootstrapModule(TimeagoModule);

我想念什么?我只是想比较HTTP调用返回的两个项目的结果,如果它们不同,请更新这些项目并刷新自上次更新以来的时间。

0 个答案:

没有答案