Angular 一段时间以前没有刷新

Angular 一段时间以前没有刷新,angular,angular2-moment,Angular,Angular2 Moment,每次调用函数“resetDate”时,我都试图刷新amTimeAgo,但它不起作用。它正在控制台中记录正确的新时间,但该时间不会刷新页面 import { NgModule, Component, OnInit } from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {platformBrowserDynamic} from '@angular/plat

每次调用函数“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);
从'@angular/core'导入{NgModule,Component,OnInit};
从“@angular/platform browser”导入{BrowserModule};
从“@angular/platformBrowserDynamic”导入{platformBrowserDynamic};
从'angular2 moment'导入{MomentModule};
从'@angular/common/http'导入{HttpClient};
@组成部分({
选择器:'应用程序根',
templateUrl:“./app.component.html”,
样式URL:['./app.component.css']
})
导出类AppComponent{
getSystemsStatus(){
this.httpClient.get('http://127.0.0.1:5000/systemsStatus)。订阅(数据=>{
if(JSON.stringify(this.systemStatusText)==JSON.stringify(data.systemStatusText)){
}
否则{
this.systemStatus=data.systemStatus;
this.systemStatusText=data.systemStatusText;
让callTimeagoComponent=new TimeagoComponent();
callTimeagoComponent.resetDate();
}
});
};
}
}
@组成部分({
选择器:“lastUpdated”,
模板:“上次更新:{{myDate | amTimeAgo}}”
})
导出类TimeagoComponent{
myDate=新日期();
重置日期(){
this.myDate=新日期();
}
}
@NGD模块({
进口:[
浏览器模块,
动量模块
],
声明:[TimeagoComponent],
引导:[TimeagoComponent]
})
类TimeagoModule{}
platformBrowserDynamic().bootstrapModule(timeagodule);

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

能否共享您的子时间组件code@Chellappan我更新了代码。我使用的另一个类进行HTTP调用,但除了调用resetDate()之外,没有处理amTimeAgo。如何在不调用resetDate()的情况下升级ui对不起,我忽略了试图简化问题所在的部分,但我可以看出这让人困惑。我添加了调用resetData()函数的地方。在angular中,如果要共享数据,必须使用服务或输入、输出属性绑定