如何获取使用 AngularJS 动态存储的隐藏输入值
How to get hidden input value that was dynamically stored using AngularJS
我正在尝试为 "chat channels" 实现 search method
,对于每个查询,它代表 SQL table
与 database.Each 结果的兼容结果可以通过独特的 ID
也来自 SQl
table.I 不想显示 ID's
所以我将它们放在 hidden input
中使用 ng-model
。此外,对于每个结果,用户都有可能 订阅 到此结果中显示的频道(订阅按钮),因此为了正确保存订阅,我需要得到保存在相同结果的hidden input
中的ID
。
这是我尝试过的:
<table class="table table-condensed">
<tr class="separating_line" ng-repeat="x in result">
<!-- ng-bind-html allows to bind a variable to the innerHTML part of the HTML element -->
<td>
<div class="col-md-8">
<h4><b style="color: gray;">{{ x.Name }}</b></h4>
<br><p> {{ x.Description }}</p>
</div>
<div class="col-md-2">
<small><label style="color: gray;">Subscribers </label>{{ x.Subscribersnum }}</label></small><br>
<input id="hiddenId" hidden="hide" ng-model="idval=x.ChanID" />
<button ng-click="subscribechannel()" class="btn btn-primary">Subscribe</button>
</div>
</td>
</tr>
</table>
在controller
我按以下方式发送方便Servlet
:
$http.get("http://localhost:8080/ExampleServletv3/subscribeservlet",{
params: {
subidval: $scope.idval
}
})
但是在调试时,我在 servlet
中得到的值是 null
。
我该如何解决这个问题?有什么想法吗?
谢谢
你不需要任何隐藏字段来做你想做的事。您只需要将一个参数传递给您的函数即可:
<tr class="separating_line" ng-repeat="x in result">
...
<button ng-click="subscribechannel(x)" class="btn btn-primary">Subscribe</button>
我正在尝试为 "chat channels" 实现 search method
,对于每个查询,它代表 SQL table
与 database.Each 结果的兼容结果可以通过独特的 ID
也来自 SQl
table.I 不想显示 ID's
所以我将它们放在 hidden input
中使用 ng-model
。此外,对于每个结果,用户都有可能 订阅 到此结果中显示的频道(订阅按钮),因此为了正确保存订阅,我需要得到保存在相同结果的hidden input
中的ID
。
这是我尝试过的:
<table class="table table-condensed">
<tr class="separating_line" ng-repeat="x in result">
<!-- ng-bind-html allows to bind a variable to the innerHTML part of the HTML element -->
<td>
<div class="col-md-8">
<h4><b style="color: gray;">{{ x.Name }}</b></h4>
<br><p> {{ x.Description }}</p>
</div>
<div class="col-md-2">
<small><label style="color: gray;">Subscribers </label>{{ x.Subscribersnum }}</label></small><br>
<input id="hiddenId" hidden="hide" ng-model="idval=x.ChanID" />
<button ng-click="subscribechannel()" class="btn btn-primary">Subscribe</button>
</div>
</td>
</tr>
</table>
在controller
我按以下方式发送方便Servlet
:
$http.get("http://localhost:8080/ExampleServletv3/subscribeservlet",{
params: {
subidval: $scope.idval
}
})
但是在调试时,我在 servlet
中得到的值是 null
。
我该如何解决这个问题?有什么想法吗?
谢谢
你不需要任何隐藏字段来做你想做的事。您只需要将一个参数传递给您的函数即可:
<tr class="separating_line" ng-repeat="x in result">
...
<button ng-click="subscribechannel(x)" class="btn btn-primary">Subscribe</button>