<script src="" https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js ""></script>
<script>
var app = angular.module('role', []);
app.controller('fooController', function($scope) {
$scope.roles = [{
id: 1,
name: "Administrator"
}, {
id: 2,
name: "Student"
}, {
id: 3,
name: 'worker'
}];
$scope.user = {};
$scope.value=function(){
$scope.user = [name:'abc',roles:[{
id: 2,
name: 'Student'
}, {
id: 3,
name: 'worker'
}];
}
});
</script>
<body>
<button type="button" ng-click="value()">Click me </button>
<form ng-repeat="test in user">
<input type="text" ng-model="test.name">
<select multiple class="form-control" data-ng-model="user.roles" required>
<option ng-repeat="role in roles" value="{{role.id}}">{{role.name}}</option>
</select>
</body>
ng-modelでdefalutでバインドする必要があります。ng-repeatだけを使用したいデフォルトではng-optionsではありません。 $ scope.user.roles多分これがお手伝いしますng-modelとng-repeatで複数のデフォルトを選択
あなたが直面している問題は何ですか? – Sankar
選択する$ scope.user.rolesの値 –
$ scope.user.rolesの値をデフォルトで選択したい場合 – Sankar