我正在构建一个使用IndexedDB在本地存储数据的Angular + TypeScript应用程序。
我有一个Angular指令,它将scope变量的值设置为从IndexedDB请求返回的一些数据。 这非常简单,并执行如下操作:
指令A:
// getGroup() is making the requests to IndexedDB: this.dataService.getGroup().then((groupOne) => { this.scope.items = groupOne.items; });指令B:
groupOne.items.push("a new item"); this.dataService.updateGroup(groupOne).then(() => { // groupOne has been changed! // how can I let Directive A know about this, so Directive A can update its scope.items? });Directive A:
// getGroup() is making the requests to IndexedDB: this.dataService.getGroup().then((groupOne) => { this.scope.items = groupOne.items; });Directive B:
groupOne.items.push("a new item"); this.dataService.updateGroup(groupOne).then(() => { // groupOne has been changed! // how can I let Directive A know about this, so Directive A can update its scope.items? });Of course, Directive A does not know about the changes Directive B made to groupOne unless it does another request. And therefore, my view is "static".
I know I could wrap Directive A's IndexedDB request into an interval and be checking for updates, but that seems like a strange way to solve this problem.
Is there a way with IndexedDB to be notified of this change? Is there something Angular provides that could help with this (something similar to $scope.$watch()) ?
最满意答案
还没有一种方法可以用纯粹的IndexedDB来做到这一点,但它正在被原型化。 这个名字是“观察者”。 如果你喜欢,你可以尝试使用polyfill 。
There is not yet a way to do this with pure IndexedDB but it is being prototyped. The name is "Observers". You can try to use the polyfill if you are so inclined.
更多推荐
发布评论