我想要從我的結果中選擇所有選擇,以便在我的控制器中使用。如何從控制器中的多個選擇選項中獲取值
<div class="form-group" ng-repeat="att in arr track by $index" ng-hide="check">
<div class="col-md-3">
<label for="phone">{{att.name}}</label>
</div>
<div class="col-md-9">
<select class="form-control" ng-model="user.charactValue" multiple="true">
<option ng-repeat="itemss in att.value track by $index" value="{{itemss}}" >{{itemss}}</option>
</select>
<div class="text-center"><a data-toggle="modal" data-target="#addNewCharacteristic" ng-click="getObj(att)">Добави</a></div>
</div>
</div>
<input type="submit" ng-click="companyBusinessAsset">
$scope.companyBusinessAsset = function() {
console.log ($scope.charactValue);
// this return Undefined
};
向下代碼正在使用,但每次都進入if。
$scope.charactValue = [];
$scope.$watch ('selected', function(nowSelected) {
$scope.selectedValues = [];
console.log(nowSelected)
// this return Undefined
console.log('dddd')
if (!nowSelected) {
console.log("IFFFFFF");
return;
}
angular.forEach ($scope.charactValue, function(val) {
console.log(val);
$scope.charactValue.push (val.id.toString());
});
});
此代碼的工作,但我有3多個選擇選項,在ng-repeat每個選擇具有相同的ng-model.I僅在一個多選選項上獲得結果。 –
然後在瀏覽器中使用firebug/developer explorer檢查你的id的/ ng-models的select元素。他們應該是彼此獨一無二的 –