Anguar2

时间:2017-01-16 12:48:58

标签: angular

我正在使用类来控制Angular2项目中的对象。 其中一个对象是案例:

export class Case {
constructor(
    public Id: string,
    public Sagsnummer: string,
    public Titel : string,
    public Sagsstatus: string,
    public LastChange: string,
    public Sagsbehandler: Sagsbehandler,
) {}
}

我在我的服务中使用它如下:

caseChanged = new EventEmitter < Case > ();
private case :Case;

getCase(id) {
   //what I would like to do is NOT both have this const AND the class Case.
   //I would like to make the const select from the class Case 
   //instead of writing it again
   const select = {
        "Id": "",
        "Sagsnummer": "",
        "Titel": "",
        "Sagsstatus": "",
        "LastChange": ""
    };
     //params are set to get the specific json-structure from the service 
    let params = new URLSearchParams('');
    let select_encode = JSON.stringify(select);
    params.set('model.select', select_encode);

    return this.http.get(url + id, { search: params })
        .map((response: Response) => response.json())
        .subscribe(
            (data: Case) => { 
                this.case = data;
                this.caseChanged.emit(this.case);
            });
}

变量&#39;选择&#39;作为参数发送应该包含类的json结构。

因此请求URL是我想要构建的URL。 它应该如下:     https://testsite.mine/api/sag/229c89f9-b083-40bf-afcc-b96aa6fb4b8d?model.select=%7B%22Id%22:%22%22,%22Sagsnummer%22:%22%22,%22Titel%22:%22%22,%22Sagsstatus%22:%22%22,%22LastChange%22:%22%22%7D

我想从Case类中获取参数model.select的内容,而不是再次编写它。 知道怎么做到这一点吗?

0 个答案:

没有答案