我在同步我的过滤器时遇到了问题。我订阅了ActivatedRoute
的queryParams
,然后获取了query
和我的三个过滤条件。
ngOnInit() {
this.route
.queryParams
.subscribe(queryParams => {
this._query = queryParams['query'];
this._heightFilter = queryParams['height'];
this._colourFilter = queryParams['colour'];
this._weightFilter = queryParams['weight'];
// Do some request to WS to get the new data
});
}
每当我点击过滤器,比如 colour:blue
,我调用我的 reloadPage()
并提供新的 queryparams
,然后导航到同一页,只是使用新的 queryparams
。
private reloadPage(): void {
const queryParams: NavigationExtras = {};
queryParams['query'] = this._query;
//Bring filter arrays into shape for queryParams
this.prepareFiltersForParams(queryParams);
this.router.navigate([], {
queryParams,
});
这一切都很顺利。现在我们选择了
colour:blue
,但我也想要colour:orange
。我将把它添加到queryParams['colour']
中,其中包含blue
和orange
。但由于某种原因,orange
甚至存在于queryParams['colour']
中,它也没有添加到URL中。如果我现在添加另一个标准的筛选器,比如说height
,一切都很好,并且height
过滤器将被添加,colour:orange
也会被添加。
我觉得问题在于this.route.queryParams.subscribe
的change detection
无法捕获queryParams['colour']
的更改,因此不会更新。
我还在angular#17609上提出了问题。
www.awesome.org/search?query=AppleTree&colour=blue,orange
请参阅 angular#17609。 - tschaka1904