angular2 如何在使用填充搜索表单后刷新页面后获取查询参数?

angular2 how to get queryparams after refresh page once used fill search form?

当我提交搜索表单时,url 查询参数会发生变化。

当我刷新页面时,我想要获取查询参数,自动完成搜索表单。

但我不想订阅更改,因为我只想获取它一次。

这是我的搜索模型:

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?
}

您只能使用 first 订阅第一个活动。 subscribe 回调只会被调用一次:

this.activatedRoute.queryParams.first().subscribe(params => {
    // do something
})