【发布时间】:2023-01-12 11:53:51
【问题描述】:
我有两个从父组件调用的子组件:
HTML
<app-profile-form [profile]="profile"></app-profile-form>
<app-profile-activity-list [profile]="profile"></app-profile-activity-list>
这很好用;现在在第二个组件中,我有一个活动日志列表,如下所示:
HTML
<app-datatable
[headers]="['#', 'New value','Old value','Description']" [dataLength]="datalength"
[data]="profileActivities"
emptyTableMessage="No logs created">
<tr body *ngFor="let profileActivity of profileActivities; index as i">
<td scope="row">{{ i + 1 }}</td>
<td>{{profileActivity.newValue}}</td>
<td>{{profileActivity.oldValue}}</td>
<td>{{profileActivity.description}}</td>
</tr>
</app-datatable>
TS:
export class ProfileActivityListComponent implements OnInit {
@Input() profile: ProfileModel;
profileActivities: ProfileActivity[];
constructor(
public apiService: ApiService,
) { }
ngOnInit() {
let profileActivityRequestModel = {
profileId: this.profile.id,
...this.pagination
}
this.profileRequest = profileActivityRequestModel;
this.apiService.profileActivityService.getPagedFilteredList(this.profileRequest).subscribe((result) => {
this.profileActivities = result.resourceModel;
this.datalength = this.profileActivities.length;
let totalPages = result.total ? Math.ceil(result.total / result.limit) : 1;
this.pagination = {
...this.pagination,
total: result.total,
totalPages: totalPages,
page: result.offset + 1
}
});
}
最后,在第一个子模型中,我有一个表单,在一天的最后,调用 API 并返回如下响应:
TS
submitForm() {
this.store.dispatch(new ProfileActions.AddProfile(newProfile));
}
对 API 的最后一次调用将第二个子组件应检索的数据插入到数据库中。但在我刷新页面之前,更改不会反映出来。有没有办法在第一个组件提交后刷新第二个组件表信息?
【问题讨论】:
标签: angular typescript