【发布时间】:2019-06-07 16:12:47
【问题描述】:
我正在尝试根据从服务中检索到的列表刷新我的 UI。像这样:
HTML 部分:
<li *ngFor="let test of testsList" class="list-inline-item">
<div class="row m-row--no-padding align-items-center">
<div class="col">
<button
[disabled]="test.locked"
[ngClass]="{locked: test.locked, disabled: test.status == 1}"
(click)="selectTest(test)"
class="square"></button>
</div>
</div>
</li>
我的 testsList 来自 API 上的一个承诺,它在 ngOninit 中被检索:
this._myService.getAllTests().then((tests: TestDto[]) => {
this.testsList = tests;
}
从一个子组件,我想回到这个组件(根组件)并绘制更新的测试列表。要导航回父组件,我使用router.navigate(...):
this._router.navigate(['app/tests/all']);
后台数据正在更新,因为我可以签入数据库以及手动刷新页面时。但是当我导航到它时,UI 没有显示更改...
我尝试了几种方法,例如this、this,还尝试了this one,但我认为我没有以正确的方式实现它...
作为附加信息,我附上页面结构:
/tests (root page)
|
(child pages)
|----> all
|---->description
|---->....
|---->summary
我从/all跳转到/summary,我更新了/summary中的一些数据,这些数据在跳转回/all页面时必须呈现。
如何刷新 UI 或绑定到值,以便在调用 'app/tests/all' 页面时更新?
编辑:
getAllTests() {
return new Promise((resolve, reject) => {
this._testsService.getAllTests().subscribe( (result) => {
this.tests = this.orderAsc(result.items);
resolve(this.tests);
}, error => {
console.log('No tests loaded from Database');
reject();
});
});
}
【问题讨论】:
-
ChangedetectorRef.detectChanges()
标签: angular angular-ui-router angular2-routing