[英]Multiple select with track by behaving differently in angular to 1.4.x
[英]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將值的類型插入到值屬性中,並產生以下值: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>
您必須添加跟蹤來避免這種情況:
<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
使用您的值而不會遇到麻煩
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.