[英]angular 1.4.x ngOptions insert the type of the value into value attr
[英]Multiple select with track by behaving differently in angular to 1.4.x
我已經將產品從Angular 1.2.x更新到1.4.x。
將angularjs更新為1.4.x之后; 在這里我面臨問題
我所擁有的 :我添加了角度為1.2.0的代碼段,這是帶有相同代碼的1.4.8的JSFIDDLE 。
說明 :
從多選框中選擇任何一個用戶,使其處於活動狀態。 選擇第二個用戶(使用ctrl鍵)。
觀察值:1.2.x:第一個選擇的值仍處於活動狀態(true)1.4.x:在選擇第二個值之后,第一個值處於活動狀態標志將被重置。
為什么會這樣呢? 我應該怎么做才能在1.4.x中獲得現有的(1.2.x)輸出
注意:我的英文寫作不太好。 請避免語法錯誤或予以糾正:)
謝謝!
var app = angular.module('test',[]); app.controller('selectIssue',function($scope){ $scope.users = [{ name:"Rohit", active:false }, { name:"Virat", active:false }, { name:"Viky", active:false }]; $scope.selectedName = []; })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js"></script> <div ng-app="test"> <div ng-controller="selectIssue"> <div> <select multiple ng-model="selectedName" ng-options="user.name for user in users track by user.name"></select> </div> Selected value table : <div> <table border="1"> <tr> <td>Name</td> <td>isActive</td> <td>Output</td> </tr> <tr ng-repeat="n in selectedName"> <td>{{n.name}}</td> <td><input type="checkbox" ng-model="n.active"></td> <td>{{n}}</td> </tr> </table> </div> </div> </div>
更改復選框時,您不是在更新$ scope.names,而是在更新$ scope.selectedNames。 這意味着您還必須在復選框上使用ng-change來更新$ scope.names。
$scope.updateName = function(name) {
angular.forEach($scope.names, function(n) {
if (n.name === name.name) {
n.active = name.active
}
})
}
這是更新的小提琴
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.