1.4角.在value attr中插入值的类型
angular 1.4.x ngOptions insert the type of the value into value attr
我使用的是angularjs 1.4.3,当我使用ngOPtions时,angular会把值的类型插入到value属性中。
你可以在这里看到:http://jsfiddle.net/8bqfq9eb/9
我想要的:插入值没有它的类型。
问题是,ngOptions将值的类型插入到value属性中,并生成如下:number:n (n是一个数字,现在这是id)。
JS:
//used version 1.4.3
var myapp = angular.module('myapp', []);
myapp.controller('FirstCtrl', function ($scope) {
$scope.box = {};
$scope.box.people = [
{ id: 1, first: 'John', last: 'Rambo', actor: 'Silvester' },
{ id: 2, first: 'Rocky', last: 'Balboa', actor: 'Silvester' },
{ id: 3, first: 'John', last: 'Kimble', actor: 'Arnold' },
{ id: 4, first: 'Ben', last: 'Richards', actor: 'Arnold' }
];
$scope.box.selectedPerson = $scope.box.people[0].id;
});
HTML: <form method="POST">
<div ng-app="myapp">
<fieldset ng-controller="FirstCtrl">
<select name="selectedPerson" id='sel'
ng-options="p.id as p.first for p in box.people track by p.id"
ng-model="box.selectedPerson"></select>
{{ box.selectedPerson }}
<div class="show" ng-click="show();"></div>
<input type="submit" />
</fieldset>
</div>
</form>
你必须添加一个track by来避免这种情况:
<select name="selectedPerson" id='sel'
ng-options="p.id as p.first for p in box.people track by p.id"
ng-model="box.selectedPerson"></select>
但是不管怎样,这种用AngularJS生成HTML的新方法对你的ng-model
没有影响。这意味着在ng-model
工作小提琴
相关文章:
- 将样式表插入iframe
- Ckeditor-plugin:插入虚假元素add不情愿<p>标签前后
- 为什么会出现错误;未捕获的类型错误:undefined不是函数;
- 在plone 5中将自定义的灵活性内容类型插入到tinymce编辑器中
- 如何使用JavaScript检查HTML表中插入的值的类型
- 电话间隙.正在向数据库表中插入Null值.数据类型冲突
- 如何在文本框中插入数字而不是选项类型
- 未捕获的类型错误:无法在“CSSStyleSheet”上执行“插入规则”:需要 2 个参数,但仅存在 1 个参数
- 通过打开<输入类型 = “文件”>将照片插入
- JQuery 通过表单输入类型=“文件”提交后检测插入的图像
- 如何从输入类型=文件获取数据,修改它,然后将其插入到此输入JS中
- 如何在jsp中插入单选按钮、复选框和其他输入类型
- 如何将原始Javascript插入自定义内容类型的Omega模板
- 插入到DOM中的SVG元素被忽略(其类型被更改)
- 重载类型/插入键的JavaScript最大长度验证
- 在数据库中插入clob数据或所有类型的文件存储
- 为什么Chrome for iOS插入图像/webp内容类型
- 如何通过JSON在MySQL中插入Date类型变量
- 1.4角.在value attr中插入值的类型
- 如何使用suitescript在netsuite中插入汇率类型记录