【发布时间】:2017-06-27 19:55:12
【问题描述】:
目前,我尝试通过 Ngrx 商店学习 Angular。在查看样本后,我想出了以下内容。 (完整源码https://github.com/sebfischer83/Cointo/tree/master/angular/src)
我有一个容器组件,其中包含存储并从数据库加载实体。
@Component({
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './materials-Page.component.html',
styleUrls: ['./materials-Page.component.css']
})
export class MaterialsPageComponent implements OnInit {
materials$: Observable<MaterialDto[]>;
constructor(private _store: Store<fromRoot.AppState>) {
this.materials$ = _store.select(fromRoot.getMaterialsEntities);
}
ngOnInit() {
this._store.dispatch(new LoadMaterialsAction());
}
但也许我理解有问题,现在每次更改此组件时,ngOnInit 中的调度都会从服务器重新加载所有数据,因此每次单击此页面时我的商店都会刷新。但它不应该使用商店中已经存在的数据吗?
【问题讨论】:
标签: angularjs reactive-programming ngrx