From 64ac470c9662518cee79053c66090cf1ecaa9660 Mon Sep 17 00:00:00 2001 From: Meli Date: Tue, 11 Aug 2015 14:16:13 +1000 Subject: [PATCH] docs(select): explain how to set default value Setting the default value in a select is a real trap for beginners, questions about how to do this on StackExchange have been view more than 40000 times in the last year. This changes updates the documentation to make it clearer. --- src/ng/directive/select.js | 51 +++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/src/ng/directive/select.js b/src/ng/directive/select.js index 1162af9e486c..2c72166027b8 100644 --- a/src/ng/directive/select.js +++ b/src/ng/directive/select.js @@ -107,7 +107,22 @@ var SelectController = * * @description * HTML `SELECT` element with angular data-binding. - * + * + * The `select` directive provides support for {@link ngModel.NgModelController NgModelController} to + * read and write the selected value(s) of the '` element. This element will then represent the `null` or "not selected" * option. See example below for demonstration. + * + * ### Example use of select with default value set + * + +
+
+ + +
+ + Required! +
+
+
+ option = {{data.selectedOption}}
+ myForm.mySelect.$valid = {{myForm.mySelect.$valid}}
+ myForm.mySelect.$error = {{myForm.mySelect.$error}}
+ myForm.$valid = {{myForm.$valid}}
+ myForm.$error.required = {{!!myForm.$error.required}}
+
+ * * *
* The value of a `select` directive used without `ngOptions` is always a string.