ts变量值也发生变化,但是视图没有同步更新。

解决办法:

import { ChangeDetectorRef, Component, OnInit } from '@angular/core';

 

constructor(private  changeDetectorRef:ChangeDetectorRef) {}
getIndex(activeIndex: any) {
      this.dotIndex = activeIndex;
    this.changeDetectorRef.markForCheck();
    this.changeDetectorRef.detectChanges();
  }

在数据更新后添加如下代码:

this.changeDetectorRef.markForCheck();
this.changeDetectorRef.detectChanges();

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐