duanlun2827 2014-08-15 21:53
浏览 51
已采纳

在Angular控制器中进行Restangular POST之前更改表单数据

I have a form where I need to edit input values. For instance, I have a number of input controls that I want to change the value before the POST happens. I my html:

<input type="text" name="bar" id="bar" ng-model="foo.bar"/>

My Go struct:

type Foo struct{
  Bar string `json:"bar"`
}

My Angular controller:

Restangular.all('drugs/new').post($scope.drug).then(......

Before I call .post(), I want to get the input element and set a value. When I do so, right before this POST call, the new value does not get sent in the json.

  • 写回答

1条回答 默认 最新

  • doz59484 2014-08-16 13:02
    关注

    I'm assuming that the value of $scope.drug relates directly to the values of those inputs because otherwise you would have posted the relevant code, wouldn't you.

    AngularJS provides 2-way bindings which means that if the value of $scope.drug depends directly on the input elements you mention, then the relation also goes in the other way i.e. if you change the value of $scope.drug, then the inputs will change.

    So the solution is simple; change the value of $scope.drug.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 nslt的可用模型,或者其他可以进行推理的现有模型
  • ¥15 arduino上连sim900a实现连接mqtt服务器
  • ¥15 vncviewer7.0安装后如何正确注册License许可证,激活使用
  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并2
  • ¥66 关于人体营养与饮食规划的线性规划模型
  • ¥15 基于深度学习的快递面单识别系统
  • ¥15 Multisim仿真设计地铁到站提醒电路
  • ¥15 怎么用一个500W电源给5台60W的电脑供电
  • ¥15 请推荐一个轻量级规则引擎,配合流程引擎使用,规则引擎负责判断出符合规则的流程引擎模板id
  • ¥15 Excel表只有年月怎么计算年龄