Improve this Doc View Source select.SelectController

  1. type in module ng

Overview

The controller for the select directive. The controller exposes a few utility methods that can be used to augment the behavior of a regular or an ngOptions select element.

Methods

  • $hasEmptyOption();

    Returns true if the select element currently has an empty option element, i.e. an option that signifies that the select is empty / the selection is null.

  • $isUnknownOptionSelected();

    Returns true if the select element's unknown option is selected. The unknown option is added and automatically selected whenever the select model doesn't match any option.

  • $isEmptyOptionSelected();

    Returns true if the select element has an empty option and this empty option is currently selected. Returns false if the select element has no empty option or it is not selected.

Examples

Set a custom error when the unknown option is selected

This example sets a custom error "unknownValue" on the ngModelController when the select element's unknown option is selected, i.e. when the model is set to a value that is not matched by any option.

Set the "required" error when the unknown option is selected.

By default, the "required" error on the ngModelController is only set on a required select when the empty option is selected. This example adds a custom directive that also sets the error when the unknown option is selected.

© 2010–2020 Google, Inc.
Licensed under the Creative Commons Attribution License 3.0.
https://code.angularjs.org/1.8.2/docs/api/ng/type/select.SelectController