I am using jQuery to select all options of multiple select and get it's value. I want to use the same logic using angularjs.
Here's my code:
$scope.selectedAll = function(){
$('#userprofile option').each(function(){
$(this).prop('selected', true);
});
$scope.user.profile = $('#userprofile').val();
}
Here's what I've tried:
$scope.selectedAll = function() {
$scope.$watch('selected', function(nowSelected) {
$scope.user.profile = [];
// if(!nowSelected){
// return;
// }
angular.forEach(nowSelected, function(val){
$scope.user.profile.push(val.id);
});
});
}