当我提交搜索表单时,网址查询参数将会更改。
当我刷新页面时,我想获取查询文件,自动填写搜索表单。
但我不希望订阅被更改,因为我想只获得一次。
这是我的搜索模型:
constructor(
private formBuilder: FormBuilder,
private router: Router,
private activatedRoute: ActivatedRoute
){
this.searchForms = this.formBuilder.group({
cardId: [],
cardType: [],
beginTime: [],
endTime: []
});
// this.activatedRoute.queryParams.getValue()
// I want use getValue method, But it throw a error msg:
// "Property 'getValue' does not exist on type 'Observable<Params>'"
// I do not know this method is correct.
// Or have ohter better implementations.
// And when i get queryparams, how to set the search model?
}
答案 0 :(得分:1)
您只能使用first
订阅第一个活动。并且subscribe
回调只会被调用一次:
this.activatedRoute.queryParams.first().subscribe(params => {
// do something
})