1

客户:

我确实像这样在angular2中发帖:

doSelectMessagesAttributesUrl2(pushRequest : PushRequest) {
    console.info("sending post request");

    let headers = new Headers({
        'Content-Type': 'application/json'});

    return this.http
        .post(this.selectMessagesAttributesUrl, JSON.stringify(pushRequest), {headers: headers})
        .map(res => res.json().data)
        .subscribe(
            data => { },
            err => {  }
        );
}

我应该如何更改使用 FormParam 调用服务器的请求?

服务器:

 @Path("/FeatureGetQueueData")
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    @Produces(MediaType.APPLICATION_JSON)
    public String runFeatureGetQueueData(@FormParam("queue") MyString paramQueue) throws Exception {

        if (!SupporToolAlert.validateEnvironment(SupporToolConfig.ROW)) {
            return SupporToolAlert.invalidEnvironment();
        }

        String queue = PushQueueConfig.conf().QUEUE.get(paramQueue.value);
4

1 回答 1

0

您是否将您的表格与任何模型结合在一起?

在文档中你可以搜索很好的例子:就在这里

但是如果你不想为你的表单创建类,你可以这样做:

将表单中的每个元素添加到对象,并通过 http 发送该对象。

像这样的东西:

form.html

<form>
 <div class="form-group">
            <label for="status"> Status: </label>
            <input id='status' type="text" class="form-control" [ngModel]="formModel.operatorStatus" (ngModelChange)="changeFormModel('status', $event)" >
          </div>
</form>

现在在你的组件中,你需要初始化空对象来包含来自模型的数据并实现 changeFormModel:

component.ts

private formModel: any = {};
private changeFormModel(model, event) {
    this.formModel[model] = event;
}

现在在您的 http 请求中,您可以发送 formModel,记得将其字符串化;)

那不是一个完美的解决方案,但对我来说就像魅力一样,但在不久的将来我会从文档中实现一个解决方案。

我希望它对你有帮助;)

于 2016-08-18T08:02:17.377 回答