Vat*_*ato 1 ngrx angular angular-ngrx-data
我正在尝试使用ngrx-data-lab作为我项目的示例。
这是我使用的项目的stackblitz。
我无法使用我正在使用的服务器的实际 url。该网址属于我公司。但是发生的事情是服务器将随机生成的数据返回给应用程序。问题是存储中的实体不会被替换,而是被加起来。每次刷新英雄页面时,服务器都会带来新数据并将其与旧数据连接起来。
在entity-store.module.ts 中,我将defaultDataServiceConfig root 和 Hero urls更改为我的服务器。getAll() 有效,但正如我再次所说,它将数据连接到旧数据。
root: 'api', // default root path to the server's web api
// Optionally specify resource URLS for HTTP calls
entityHttpResourceUrls: {
// Case matters. Match the case of the entity name.
Hero: {
// You must specify the root as part of the resource URL.
entityResourceUrl: 'api/hero/',
collectionResourceUrl: 'api/heroes/'
}
},
Run Code Online (Sandbox Code Playgroud)
如何让 getAll 替换旧数据而不是连接它?
我的错。在多次重新创建我的项目之后。我发现 getAll 将始终合并本地和远程实体。替换您必须使用的实体加载。
得到所有
/**
* Dispatch action to query remote storage for all entities and
* merge the queried entities into the cached collection.
* @param [options] options that influence merge behavior
* @returns Observable of the collection
* after server reports successful query or the query error.
* @see load()
*/
getAll(options?: EntityActionOptions): Observable<T[]> {
return this.dispatcher.getAll(options);
}
Run Code Online (Sandbox Code Playgroud)
加载
/**
* Dispatch action to query remote storage for all entities and
* completely replace the cached collection with the queried entities.
* @param [options] options that influence load behavior
* @returns Observable of the collection
* after server reports successful query or the query error.
* @see getAll
*/
load(options?: EntityActionOptions): Observable<T[]> {
return this.dispatcher.load(options);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
665 次 |
| 最近记录: |