[英]Get angular ng-model value in javascript
我想用javascript获取ng-model隐藏字段值。
<input type="hidden" name="Latitude" id="sLatitude" ng-model='sLatitude'>
it took me some time to find out, but I think the answer is 我花了一些时间才发现,但我认为答案是
angular.element(YOUR_ANGULAR_ELEMENT_HERE).attr('ng-model');
As an answer you 'll get the value of the ng-model, "sLatitude". 作为答案,您将获得ng-model的值,“sLatitude”。
I am leaving it here just in case someone else needs it. 我将它留在这里以防万一其他人需要它。
你可以通过以下方式获得sLatitude值:
console.log($scope.sLatitude);
If you want that value within scope , just access as $scope.sLatitude
如果您想在范围内使用该值,只需访问
$scope.sLatitude
If you want that value outside the scope, document.getElementById("sLatitude").value
如果您希望该值超出范围,
document.getElementById("sLatitude").value
您可以通过以下方式访问:
angular.element(document.getElementById('sLatitude')).scope().sLatitude
You can get the value of Latitude by write this in java script in your controller like this. 您可以通过在控制器的java脚本中写这个来获取Latitude的值。 var latotudeValue = $scope.sLatitude;
var latotudeValue = $ scope.sLatitude;
You can get the value of Latitude by $scope. 您可以通过$ scope获取Latitude的值。
var latitudeValue = $scope.sLatitude; var latitudeValue = $ scope.sLatitude;
OR 要么
if you have value attribute in input control then 如果你在输入控件中有值属性那么
var latitudeValue = document.getElementsById("sLatitude").value; var latitudeValue = document.getElementsById(“sLatitude”)。value;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.