繁体   English   中英

在异步管道重新订阅上重建的角子组件

[英]Angular child component reconstructed on async pipe resubscription

我正在使用'ngFor'指令初始化子组件列表:

父组件:

 <div *ngFor="let item of serviceGetter.items | async; let i = index">
     <child-component [item]="item" [currentIndex]="i"></child-component>
</div>

服务:

@Injectable()
export class TermsService {

   private dataStore: {
     data: any[];
   } = { data: [] };

   get items() {
     return this._data$.asObservable();
   }

   //data are populated inside this method
   someMethod() {
      this.dataStore.data= result;
      this._data$.next(Object.assign({}, this.dataStore).data);
   }

   updateSpecificItem() {
       ....          

      this.dataStore.data[index] = {
         ...somedata,
      };
   }
}

“子组件”更改检测设置为“ OnPush”。 问题是当“ updateSpecificItem()”函数在“索引”位置的子组件被重新初始化(构造函数调用)时。 有解决方案可以避免这种情况吗?还是这是公认的行为?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM