使用AngularJS将隐藏值传递给JSON
Pass hidden values to JSON using AngularJS
我基本的开发人员,只是想通过隐藏值从我的html页面在json数组。下面是我的代码:-
index . html
<!doctype html>
<html ng-app="plunker" >
<head>
<meta charset="utf-8">
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');
</script>
<link rel="stylesheet" href="style.css">
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.5/angular.js"></script>
<script src="app.js"></script>
</head>
<body>
<div ng-controller="WorkingCtrl">
<h1 ng-bind="vm.heading"></h1>
<form name="myForm" novalidate>
<b> Text: </b>
<input ng-model="form.text" required /><br>
<button ng-click="submitForm()" bng-disabled="myForm.$invalid">Click Me!</button>
</form>
<p ng-bind="showValues"></p>
</div>
</body>
</html>
app.js
var app = angular.module('myApp');
app.controller('WorkingCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.form = {};
$scope.submitForm = function () {
$scope.showValues = JSON.stringify($scope.form);
}
}]);
现在,来自ng-model="form.text"
的值成功返回了未隐藏输入类型
{ "text":"What_ever_text" }
,但如何发送数组中定义的值,包括隐藏的输入类型,如:-
<input value="99999" type="hidden" ng-model="form.userid" required />
所以,想要的输出像:-
{ "text":"What_ever_text" , "userid":"99999" }
有答案吗?注:-输入类型应隐藏或任何其他更容易的方法赞赏。
隐藏输入字段的工作原理与普通字段相同。
见下面的代码
var app = angular.module('myApp', []);
app.controller('WorkingCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.form = {
text: "some test",
userid: '12312312312'
};
$scope.submitForm = function () {
$scope.showValues = JSON.stringify($scope.form);
}
}]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="myApp">
<div ng-controller="WorkingCtrl">
<h1 ng-bind="vm.heading"></h1>
<form name="myForm" ng-submit="submitForm()" novalidate>Text:
<input ng-model="form.text" required />
<br/>
<input type="hidden" ng-model="form.userid" required />
<button bng-disabled="myForm.$invalid">Click Me!</button>
</form>
<p ng-bind="showValues"></p>
</div>
</div>
相关文章:
- 在循环中分配json值时,值被覆盖
- 将JSON对象传递给angular指令
- 如何将输入范围的值传递给JS中的变量
- 如何将值传递给wicket中的javascript函数
- 使用javascript或angularjs特定过滤器搜索字符串中第一个img标记的json值
- 将值传递给jquery创建的输入字段
- 需要将select标记选项值传递给ajax函数
- 如何使用Ajax JQuery.ech()获取JSON值
- 可以't通过从googlemapapi获取json值
- 使用Ajax将PHP值传递给javascript
- 将javascript值传递给PHP
- 如何使用NodeJS修改文件中的JSON值
- 无法将json值从angularjs发布到php
- 如何将非json值传递给angular.jshttp.post方法
- 将文本框值传递给JS函数以转换为JSON
- 如何将 JSON 值传递给 PHP 并存储在 Mysql 中
- JSON将null值传递给IE9中的MVC 4控制器
- 将一个值传递给javascript中的一个变量,其中这些值是json中的响应
- 使用Javascript和Json将选择选项值传递给PHP并从数据库中检索数据
- 使用AngularJS将隐藏值传递给JSON