D
D
Denioo2019-07-15 09:10:33
JavaScript
Denioo, 2019-07-15 09:10:33

How to pass a function to Select option?

Hello everyone, such a problem. There is a select list with values.

<select class="form-control" id="roleFilter" name="role.id" 
                  ng-options="role.name for role in vm.roleSelectOptions"
                  ng-model="vm.selectedRole"
                  ng-change="vm.onRoleChange(vm.selectedRole)"></select>

How to add to it so that the first value is "Choice ..." for example, and when you click on it, it would clear the entire list. There is a function that does this, but it only works on the button, how can I move it to option Select ... option
function defaultRole() {
      vm.filter.roleFilter = null;
      vm.filter.useRoleFilter = false;
      search(true);
    }

Which day I suffer with this I can not think of anything.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2019-07-15
@Denioo

vm.roleSelectOptions.push({name: 'очистить', id: -1})

vm.onRoleChange(role){
...
if(role.id === -1) {
  defaultRole();
}
...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question