I want get all selected from me result,for using in my controller.
<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
};
Down code is using, but each time they enter into 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());
});
});
尝试将ng-multiple="true"
到select
。
I did this in one of my projects as below, hope this helps:
<select multiple="multiple" name="selectedRoleId" ng-model="user.selectedRole" class="form-control">
<option ng:repeat="role in roleList" value="{{role.Name}}">{{role.Name}}</option>
</select>
then in the submit function in the controller:
//declare $scope.user to avoid undefined/notfound error
$scope.user = {}; //above the function
//and inside the function
$scope.submitForm=function() {
var reguser = new models.register($scope.user);
};
you will get the multiple selected values in $scope.user
's selectedRole
property
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.