自动刷新角度分量

时间:2019-02-11 07:56:45

标签: angular

我有一个日历布局,每天一个单元。我要单击一个单元格,在当天的“假期”数据库中写上一个信息,如果成功返回响应,并且该单元格应该以不同的颜色显示。

我的问题是,仅当我刷新页面并从db中读取时,颜色才会显示...如何为组件进行自动刷新?

我有一个包含所有数据(用户,状态等)的父组件,并用它来调用服务方法,而一个子组件则用其天数表示一个月。

这是我在父组件中为此功能所做的工作:

 this.holidayClicked = function (day: CalendarMonthViewDay): Observable<boolean> {
        const username = this.user.userId;
        const holiday = new EmployeeHoliday();
        holiday.date = new Date(Date.UTC(day.date.getFullYear(), day.date.getMonth(), day.date.getDate()));
        holiday.state = that.stateSelected;
        holiday.comment = '';

        return this.calendarService.updateEmployee(username, holiday).map(
          _ => {
            if (holiday && holiday.state.stateVal !== 1) {
              return true;
            } else {
              return false;
            }
          });
      };

这是我的子组件

@Input() holidayClicked: Function;

  dayClicked(day: CalendarMonthViewDay): void {
    const sub = this.holidayClicked(day);
    sub.subscribe(isHoliday => {
      if (isHoliday === true) {
        console.log('Huuuuoooooo');
      } else {
        console.log('Hooray!!!!!!');
      }
      this.refresh.next();
    });

public refresh: Subject<any> = new Subject();

0 个答案:

没有答案