@angular-wave/angular.ts 0.0.66 → 0.0.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/dist/angular-ts.esm.js +2 -2
  2. package/dist/angular-ts.umd.js +2 -2
  3. package/package.json +1 -1
  4. package/src/animations/animate-js.js +4 -4
  5. package/src/animations/animate-swap.js +3 -0
  6. package/src/core/compile/compile.js +3 -3
  7. package/src/core/controller/controller.js +0 -5
  8. package/src/core/di/injector.js +9 -12
  9. package/src/core/di/internal-injector.js +113 -60
  10. package/src/core/interval/interval-factory.js +8 -1
  11. package/src/core/interval/interval.js +30 -16
  12. package/src/core/location/location.js +473 -626
  13. package/src/core/location/location.md +114 -0
  14. package/src/core/location/location.spec.js +1 -76
  15. package/src/core/parser/parse.js +1 -12
  16. package/src/core/parser/parse.spec.js +96 -110
  17. package/src/core/q/q.js +63 -65
  18. package/src/core/sce/sce.js +1 -3
  19. package/src/core/scope/scope.js +2 -5
  20. package/src/core/timeout/timeout.js +110 -111
  21. package/src/core/url-utils/url-utils.js +5 -0
  22. package/src/directive/input/input.js +32 -726
  23. package/src/directive/input/input.md +706 -0
  24. package/src/directive/options/options.js +2 -156
  25. package/src/directive/options/options.md +179 -0
  26. package/src/directive/select/select.js +55 -126
  27. package/src/directive/select/select.md +74 -0
  28. package/src/directive/show-hide/show-hide.js +13 -224
  29. package/src/directive/show-hide/show-hide.md +257 -0
  30. package/src/exts/messages/messages.js +2 -0
  31. package/src/filters/limit-to.spec.js +1 -1
  32. package/src/filters/order-by.spec.js +1 -1
  33. package/src/index.js +6 -2
  34. package/src/loader.js +7 -3
  35. package/src/public.js +1 -7
  36. package/src/router/params/param.js +54 -54
  37. package/src/router/path/path-utils.js +1 -0
  38. package/src/router/state/state-builder.js +2 -4
  39. package/src/router/state/state-service.js +1 -1
  40. package/src/router/state-provider.js +1 -1
  41. package/src/router/template-factory.js +10 -10
  42. package/src/router/url/url-service.js +11 -4
  43. package/src/services/anchor-scroll.js +3 -5
  44. package/src/services/browser.js +2 -9
  45. package/src/services/cache-factory.js +0 -67
  46. package/src/services/cache-factory.md +75 -0
  47. package/src/services/cookie-reader.js +36 -55
  48. package/src/services/http/http.js +62 -587
  49. package/src/services/http/http.md +413 -0
  50. package/src/services/http-backend/http-backend.js +19 -44
  51. package/src/services/template-request.js +1 -9
  52. package/src/shared/jqlite/jqlite.js +5 -70
  53. package/src/types.js +2 -4
  54. package/types/animations/animate-swap.d.ts +4 -7
  55. package/types/core/compile/compile.d.ts +6 -6
  56. package/types/core/controller/controller.d.ts +0 -5
  57. package/types/core/di/internal-injector.d.ts +73 -18
  58. package/types/core/exception-handler.d.ts +1 -1
  59. package/types/core/interval/interval-factory.d.ts +1 -1
  60. package/types/core/interval/interval.d.ts +4 -0
  61. package/types/core/location/location.d.ts +235 -166
  62. package/types/core/parser/parse.d.ts +1 -1
  63. package/types/core/q/q.d.ts +61 -40
  64. package/types/core/scope/scope.d.ts +5 -8
  65. package/types/core/timeout/timeout.d.ts +16 -26
  66. package/types/core/url-utils/url-utils.d.ts +4 -0
  67. package/types/directive/input/input.d.ts +19 -124
  68. package/types/directive/select/select.d.ts +7 -74
  69. package/types/directive/show-hide/show-hide.d.ts +11 -224
  70. package/types/loader.d.ts +4 -4
  71. package/types/router/params/param.d.ts +11 -0
  72. package/types/router/state/state-builder.d.ts +1 -2
  73. package/types/router/state/state-service.d.ts +2 -2
  74. package/types/router/state-provider.d.ts +2 -2
  75. package/types/router/template-factory.d.ts +15 -15
  76. package/types/router/url/url-service.d.ts +12 -12
  77. package/types/services/anchor-scroll.d.ts +1 -1
  78. package/types/services/browser.d.ts +0 -10
  79. package/types/services/cache-factory.d.ts +0 -67
  80. package/types/services/cookie-reader.d.ts +2 -10
  81. package/types/services/http/http.d.ts +53 -61
  82. package/types/services/http-backend/http-backend.d.ts +8 -31
  83. package/types/services/template-request.d.ts +1 -9
  84. package/types/shared/jqlite/jqlite.d.ts +11 -11
  85. package/types/types.d.ts +1 -9
@@ -11,161 +11,6 @@ import {
11
11
 
12
12
  const ngOptionsMinErr = minErr("ngOptions");
13
13
 
14
- /**
15
- * @ngdoc directive
16
- * @name ngOptions
17
- * @restrict A
18
- *
19
- * @description
20
- *
21
- * The `ngOptions` attribute can be used to dynamically generate a list of `<option>`
22
- * elements for the `<select>` element using the array or object obtained by evaluating the
23
- * `ngOptions` comprehension expression.
24
- *
25
- * In many cases, {@link ng.directive:ngRepeat ngRepeat} can be used on `<option>` elements instead of
26
- * `ngOptions` to achieve a similar result. However, `ngOptions` provides some benefits:
27
- * - more flexibility in how the `<select>`'s model is assigned via the `select` **`as`** part of the
28
- * comprehension expression
29
- * - reduced memory consumption by not creating a new scope for each repeated instance
30
- * - increased render speed by creating the options in a documentFragment instead of individually
31
- *
32
- * When an item in the `<select>` menu is selected, the array element or object property
33
- * represented by the selected option will be bound to the model identified by the `ngModel`
34
- * directive.
35
- *
36
- * Optionally, a single hard-coded `<option>` element, with the value set to an empty string, can
37
- * be nested into the `<select>` element. This element will then represent the `null` or "not selected"
38
- * option. See example below for demonstration.
39
- *
40
- * ## Complex Models (objects or collections)
41
- *
42
- * By default, `ngModel` watches the model by reference, not value. This is important to know when
43
- * binding the select to a model that is an object or a collection.
44
- *
45
- * One issue occurs if you want to preselect an option. For example, if you set
46
- * the model to an object that is equal to an object in your collection, `ngOptions` won't be able to set the selection,
47
- * because the objects are not identical. So by default, you should always reference the item in your collection
48
- * for preselections, e.g.: `$scope.selected = $scope.collection[3]`.
49
- *
50
- * Another solution is to use a `track by` clause, because then `ngOptions` will track the identity
51
- * of the item not by reference, but by the result of the `track by` expression. For example, if your
52
- * collection items have an id property, you would `track by item.id`.
53
- *
54
- * A different issue with objects or collections is that ngModel won't detect if an object property or
55
- * a collection item changes. For that reason, `ngOptions` additionally watches the model using
56
- * `$watchCollection`, when the expression contains a `track by` clause or the the select has the `multiple` attribute.
57
- * This allows ngOptions to trigger a re-rendering of the options even if the actual object/collection
58
- * has not changed identity, but only a property on the object or an item in the collection changes.
59
- *
60
- * Note that `$watchCollection` does a shallow comparison of the properties of the object (or the items in the collection
61
- * if the model is an array). This means that changing a property deeper than the first level inside the
62
- * object/collection will not trigger a re-rendering.
63
- *
64
- * ## `select` **`as`**
65
- *
66
- * Using `select` **`as`** will bind the result of the `select` expression to the model, but
67
- * the value of the `<select>` and `<option>` html elements will be either the index (for array data sources)
68
- * or property name (for object data sources) of the value within the collection. If a **`track by`** expression
69
- * is used, the result of that expression will be set as the value of the `option` and `select` elements.
70
- *
71
- *
72
- * ### `select` **`as`** and **`track by`**
73
- *
74
- * <div class="alert alert-warning">
75
- * Be careful when using `select` **`as`** and **`track by`** in the same expression.
76
- * </div>
77
- *
78
- * Given this array of items on the $scope:
79
- *
80
- * ```js
81
- * $scope.items = [{
82
- * id: 1,
83
- * label: 'aLabel',
84
- * subItem: { name: 'aSubItem' }
85
- * }, {
86
- * id: 2,
87
- * label: 'bLabel',
88
- * subItem: { name: 'bSubItem' }
89
- * }];
90
- * ```
91
- *
92
- * This will work:
93
- *
94
- * ```html
95
- * <select ng-options="item as item.label for item in items track by item.id" ng-model="selected"></select>
96
- * ```
97
- * ```js
98
- * $scope.selected = $scope.items[0];
99
- * ```
100
- *
101
- * but this will not work:
102
- *
103
- * ```html
104
- * <select ng-options="item.subItem as item.label for item in items track by item.id" ng-model="selected"></select>
105
- * ```
106
- * ```js
107
- * $scope.selected = $scope.items[0].subItem;
108
- * ```
109
- *
110
- * In both examples, the **`track by`** expression is applied successfully to each `item` in the
111
- * `items` array. Because the selected option has been set programmatically in the controller, the
112
- * **`track by`** expression is also applied to the `ngModel` value. In the first example, the
113
- * `ngModel` value is `items[0]` and the **`track by`** expression evaluates to `items[0].id` with
114
- * no issue. In the second example, the `ngModel` value is `items[0].subItem` and the **`track by`**
115
- * expression evaluates to `items[0].subItem.id` (which is undefined). As a result, the model value
116
- * is not matched against any `<option>` and the `<select>` appears as having no selected value.
117
- *
118
- *
119
- * @param {string} ngModel Assignable AngularJS expression to data-bind to.
120
- * @param {comprehension_expression} ngOptions in one of the following forms:
121
- *
122
- * * for array data sources:
123
- * * `label` **`for`** `value` **`in`** `array`
124
- * * `select` **`as`** `label` **`for`** `value` **`in`** `array`
125
- * * `label` **`group by`** `group` **`for`** `value` **`in`** `array`
126
- * * `label` **`disable when`** `disable` **`for`** `value` **`in`** `array`
127
- * * `label` **`group by`** `group` **`for`** `value` **`in`** `array` **`track by`** `trackexpr`
128
- * * `label` **`disable when`** `disable` **`for`** `value` **`in`** `array` **`track by`** `trackexpr`
129
- * * `label` **`for`** `value` **`in`** `array` | orderBy:`orderexpr` **`track by`** `trackexpr`
130
- * (for including a filter with `track by`)
131
- * * for object data sources:
132
- * * `label` **`for (`**`key` **`,`** `value`**`) in`** `object`
133
- * * `select` **`as`** `label` **`for (`**`key` **`,`** `value`**`) in`** `object`
134
- * * `label` **`group by`** `group` **`for (`**`key`**`,`** `value`**`) in`** `object`
135
- * * `label` **`disable when`** `disable` **`for (`**`key`**`,`** `value`**`) in`** `object`
136
- * * `select` **`as`** `label` **`group by`** `group`
137
- * **`for` `(`**`key`**`,`** `value`**`) in`** `object`
138
- * * `select` **`as`** `label` **`disable when`** `disable`
139
- * **`for` `(`**`key`**`,`** `value`**`) in`** `object`
140
- *
141
- * Where:
142
- *
143
- * * `array` / `object`: an expression which evaluates to an array / object to iterate over.
144
- * * `value`: local variable which will refer to each item in the `array` or each property value
145
- * of `object` during iteration.
146
- * * `key`: local variable which will refer to a property name in `object` during iteration.
147
- * * `label`: The result of this expression will be the label for `<option>` element. The
148
- * `expression` will most likely refer to the `value` variable (e.g. `value.propertyName`).
149
- * * `select`: The result of this expression will be bound to the model of the parent `<select>`
150
- * element. If not specified, `select` expression will default to `value`.
151
- * * `group`: The result of this expression will be used to group options using the `<optgroup>`
152
- * DOM element.
153
- * * `disable`: The result of this expression will be used to disable the rendered `<option>`
154
- * element. Return `true` to disable.
155
- * * `trackexpr`: Used when working with an array of objects. The result of this expression will be
156
- * used to identify the objects in the array. The `trackexpr` will most likely refer to the
157
- * `value` variable (e.g. `value.propertyName`). With this the selection is preserved
158
- * even when the options are recreated (e.g. reloaded from the server).
159
- * @param {string=} name Property name of the form under which the control is published.
160
- * @param {string=} required The control is considered valid only if value is entered.
161
- * @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
162
- * the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
163
- * `required` when you want to data-bind to the `required` attribute.
164
- * @param {string=} ngAttrSize sets the size of the select element dynamically. Uses the
165
- * {@link guide/interpolation#-ngattr-for-binding-to-arbitrary-attributes ngAttr} directive.
166
- *
167
- */
168
-
169
14
  const NG_OPTIONS_REGEXP =
170
15
  /^\s*([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+group\s+by\s+([\s\S]+?))?(?:\s+disable\s+when\s+([\s\S]+?))?\s+for\s+(?:([$\w][$\w]*)|(?:\(\s*([$\w][$\w]*)\s*,\s*([$\w][$\w]*)\s*\)))\s+in\s+([\s\S]+?)(?:\s+track\s+by\s+([\s\S]+?))?$/;
171
16
  // 1: value expression (valueFn)
@@ -618,7 +463,8 @@ export const ngOptionsDirective = [
618
463
 
619
464
  // Update the label on the group element
620
465
  // "null" is special cased because of Safari
621
- groupElement.label =
466
+ /** @type {HTMLOptGroupElement} */
467
+ (groupElement).label =
622
468
  option.group === null ? "null" : option.group;
623
469
 
624
470
  // Store it for use later
@@ -0,0 +1,179 @@
1
+ /\*\*
2
+
3
+ -
4
+ - The `ngOptions` attribute can be used to dynamically generate a list of `<option>`
5
+ - elements for the `<select>` element using the array or object obtained by evaluating the
6
+ - `ngOptions` comprehension expression.
7
+ -
8
+ - In many cases, {@link ng.directive:ngRepeat ngRepeat} can be used on `<option>` elements instead of
9
+ - `ngOptions` to achieve a similar result. However, `ngOptions` provides some benefits:
10
+ - - more flexibility in how the `<select>`'s model is assigned via the `select` **`as`** part of the
11
+ - comprehension expression
12
+ - - reduced memory consumption by not creating a new scope for each repeated instance
13
+ - - increased render speed by creating the options in a documentFragment instead of individually
14
+ -
15
+ - When an item in the `<select>` menu is selected, the array element or object property
16
+ - represented by the selected option will be bound to the model identified by the `ngModel`
17
+ - directive.
18
+ -
19
+ - Optionally, a single hard-coded `<option>` element, with the value set to an empty string, can
20
+ - be nested into the `<select>` element. This element will then represent the `null` or "not selected"
21
+ - option. See example below for demonstration.
22
+ -
23
+ - ## Complex Models (objects or collections)
24
+ -
25
+ - By default, `ngModel` watches the model by reference, not value. This is important to know when
26
+ - binding the select to a model that is an object or a collection.
27
+ -
28
+ - One issue occurs if you want to preselect an option. For example, if you set
29
+ - the model to an object that is equal to an object in your collection, `ngOptions` won't be able to set the selection,
30
+ - because the objects are not identical. So by default, you should always reference the item in your collection
31
+ - for preselections, e.g.: `$scope.selected = $scope.collection[3]`.
32
+ -
33
+ - Another solution is to use a `track by` clause, because then `ngOptions` will track the identity
34
+ - of the item not by reference, but by the result of the `track by` expression. For example, if your
35
+ - collection items have an id property, you would `track by item.id`.
36
+ -
37
+ - A different issue with objects or collections is that ngModel won't detect if an object property or
38
+ - a collection item changes. For that reason, `ngOptions` additionally watches the model using
39
+ - `$watchCollection`, when the expression contains a `track by` clause or the the select has the `multiple` attribute.
40
+ - This allows ngOptions to trigger a re-rendering of the options even if the actual object/collection
41
+ - has not changed identity, but only a property on the object or an item in the collection changes.
42
+ -
43
+ - Note that `$watchCollection` does a shallow comparison of the properties of the object (or the items in the collection
44
+ - if the model is an array). This means that changing a property deeper than the first level inside the
45
+ - object/collection will not trigger a re-rendering.
46
+ -
47
+ - ## `select` **`as`**
48
+ -
49
+ - Using `select` **`as`** will bind the result of the `select` expression to the model, but
50
+ - the value of the `<select>` and `<option>` html elements will be either the index (for array data sources)
51
+ - or property name (for object data sources) of the value within the collection. If a **`track by`** expression
52
+ - is used, the result of that expression will be set as the value of the `option` and `select` elements.
53
+ -
54
+ -
55
+ - ### `select` **`as`** and **`track by`**
56
+ -
57
+ - <div class="alert alert-warning">
58
+ - Be careful when using `select` **`as`** and **`track by`** in the same expression.
59
+ - </div>
60
+ -
61
+ - Given this array of items on the $scope:
62
+ -
63
+ - ```js
64
+
65
+ ```
66
+
67
+ - $scope.items = [{
68
+ - id: 1,
69
+ - label: 'aLabel',
70
+ - subItem: { name: 'aSubItem' }
71
+ - }, {
72
+ - id: 2,
73
+ - label: 'bLabel',
74
+ - subItem: { name: 'bSubItem' }
75
+ - }];
76
+ - ```
77
+
78
+ ```
79
+
80
+ -
81
+ - This will work:
82
+ -
83
+ - ```html
84
+
85
+ ```
86
+
87
+ - <select ng-options="item as item.label for item in items track by item.id" ng-model="selected"></select>
88
+ - ```
89
+
90
+ ```
91
+
92
+ - ```js
93
+
94
+ ```
95
+
96
+ - $scope.selected = $scope.items[0];
97
+ - ```
98
+
99
+ ```
100
+
101
+ -
102
+ - but this will not work:
103
+ -
104
+ - ```html
105
+
106
+ ```
107
+
108
+ - <select ng-options="item.subItem as item.label for item in items track by item.id" ng-model="selected"></select>
109
+ - ```
110
+
111
+ ```
112
+
113
+ - ```js
114
+
115
+ ```
116
+
117
+ - $scope.selected = $scope.items[0].subItem;
118
+ - ```
119
+
120
+ ```
121
+
122
+ -
123
+ - In both examples, the **`track by`** expression is applied successfully to each `item` in the
124
+ - `items` array. Because the selected option has been set programmatically in the controller, the
125
+ - **`track by`** expression is also applied to the `ngModel` value. In the first example, the
126
+ - `ngModel` value is `items[0]` and the **`track by`** expression evaluates to `items[0].id` with
127
+ - no issue. In the second example, the `ngModel` value is `items[0].subItem` and the **`track by`**
128
+ - expression evaluates to `items[0].subItem.id` (which is undefined). As a result, the model value
129
+ - is not matched against any `<option>` and the `<select>` appears as having no selected value.
130
+ -
131
+ -
132
+ - @param {string} ngModel Assignable AngularJS expression to data-bind to.
133
+ - @param {string} ngOptions in one of the following forms:
134
+ -
135
+ - - for array data sources:
136
+ - * `label` **`for`** `value` **`in`** `array`
137
+ - * `select` **`as`** `label` **`for`** `value` **`in`** `array`
138
+ - * `label` **`group by`** `group` **`for`** `value` **`in`** `array`
139
+ - * `label` **`disable when`** `disable` **`for`** `value` **`in`** `array`
140
+ - * `label` **`group by`** `group` **`for`** `value` **`in`** `array` **`track by`** `trackexpr`
141
+ - * `label` **`disable when`** `disable` **`for`** `value` **`in`** `array` **`track by`** `trackexpr`
142
+ - * `label` **`for`** `value` **`in`** `array` | orderBy:`orderexpr` **`track by`** `trackexpr`
143
+ - (for including a filter with `track by`)
144
+ - - for object data sources:
145
+ - * `label` **`for (`**`key` **`,`** `value`**`) in`** `object`
146
+ - * `select` **`as`** `label` **`for (`**`key` **`,`** `value`**`) in`** `object`
147
+ - * `label` **`group by`** `group` **`for (`**`key`**`,`** `value`**`) in`** `object`
148
+ - * `label` **`disable when`** `disable` **`for (`**`key`**`,`** `value`**`) in`** `object`
149
+ - * `select` **`as`** `label` **`group by`** `group`
150
+ - **`for` `(`**`key`**`,`** `value`**`) in`** `object`
151
+ - * `select` **`as`** `label` **`disable when`** `disable`
152
+ - **`for` `(`**`key`**`,`** `value`**`) in`** `object`
153
+ -
154
+ - Where:
155
+ -
156
+ - - `array` / `object`: an expression which evaluates to an array / object to iterate over.
157
+ - - `value`: local variable which will refer to each item in the `array` or each property value
158
+ - of `object` during iteration.
159
+ - - `key`: local variable which will refer to a property name in `object` during iteration.
160
+ - - `label`: The result of this expression will be the label for `<option>` element. The
161
+ - `expression` will most likely refer to the `value` variable (e.g. `value.propertyName`).
162
+ - - `select`: The result of this expression will be bound to the model of the parent `<select>`
163
+ - element. If not specified, `select` expression will default to `value`.
164
+ - - `group`: The result of this expression will be used to group options using the `<optgroup>`
165
+ - DOM element.
166
+ - - `disable`: The result of this expression will be used to disable the rendered `<option>`
167
+ - element. Return `true` to disable.
168
+ - - `trackexpr`: Used when working with an array of objects. The result of this expression will be
169
+ - used to identify the objects in the array. The `trackexpr` will most likely refer to the
170
+ - `value` variable (e.g. `value.propertyName`). With this the selection is preserved
171
+ - even when the options are recreated (e.g. reloaded from the server).
172
+ - @param {string=} name Property name of the form under which the control is published.
173
+ - @param {string=} required The control is considered valid only if value is entered.
174
+ - @param {string=} ngRequired Adds `required` attribute and `required` validation constraint to
175
+ - the element when the ngRequired expression evaluates to true. Use `ngRequired` instead of
176
+ - `required` when you want to data-bind to the `required` attribute.
177
+ - @param {string=} ngAttrSize sets the size of the select element dynamically. Uses the
178
+ - {@link guide/interpolation#-ngattr-for-binding-to-arbitrary-attributes ngAttr} directive.
179
+ - \*/
@@ -8,8 +8,6 @@ import {
8
8
  shallowCopy,
9
9
  } from "../../shared/utils";
10
10
 
11
- const noopNgModelController = { $setViewValue: () => {}, $render: () => {} };
12
-
13
11
  function setOptionSelectedStatus(optionEl, value) {
14
12
  optionEl[0].selected = value;
15
13
  /**
@@ -23,16 +21,17 @@ function setOptionSelectedStatus(optionEl, value) {
23
21
  }
24
22
 
25
23
  /**
26
- * @ngdoc type
27
- * @name select.SelectController
28
- *
29
- * @description
30
24
  * The controller for the {@link ng.select select} directive. The controller exposes
31
25
  * a few utility methods that can be used to augment the behavior of a regular or an
32
26
  * {@link ng.ngOptions ngOptions} select element.
33
27
  *
34
28
  */
35
29
  SelectController.$inject = ["$element", "$scope"];
30
+ /**
31
+ *
32
+ * @param {JQLite} $element
33
+ * @param {import('../../core/scope/scope').Scope} $scope
34
+ */
36
35
  function SelectController($element, $scope) {
37
36
  const self = this;
38
37
  const optionsMap = new Map();
@@ -40,7 +39,7 @@ function SelectController($element, $scope) {
40
39
  self.selectValueMap = {}; // Keys are the hashed values, values the original values
41
40
 
42
41
  // If the ngModel doesn't get provided then provide a dummy noop version to prevent errors
43
- self.ngModelCtrl = noopNgModelController;
42
+ self.ngModelCtrl = {};
44
43
  self.multiple = false;
45
44
 
46
45
  // The "unknown" option is one that is prepended to the list if the viewValue
@@ -105,7 +104,7 @@ function SelectController($element, $scope) {
105
104
 
106
105
  // Read the value of the select control, the implementation of this changes depending
107
106
  // upon whether the select can have multiple values and whether ngOptions is at work.
108
- self.readValue = function readSingleValue() {
107
+ self.readValue = function () {
109
108
  const val = $element.val();
110
109
  // ngValue added option values are stored in the selectValueMap, normal interpolations are not
111
110
  const realVal = val in self.selectValueMap ? self.selectValueMap[val] : val;
@@ -371,80 +370,9 @@ function SelectController($element, $scope) {
371
370
  }
372
371
 
373
372
  /**
374
- * @ngdoc directive
375
- * @name select
376
- * @restrict E
377
- *
378
- * @description
379
- * HTML `select` element with AngularJS data-binding.
380
- *
381
- * The `select` directive is used together with {@link ngModel `ngModel`} to provide data-binding
382
- * between the scope and the `<select>` control (including setting default values).
383
- * It also handles dynamic `<option>` elements, which can be added using the {@link ngRepeat `ngRepeat}` or
384
- * {@link ngOptions `ngOptions`} directives.
385
- *
386
- * When an item in the `<select>` menu is selected, the value of the selected option will be bound
387
- * to the model identified by the `ngModel` directive. With static or repeated options, this is
388
- * the content of the `value` attribute or the textContent of the `<option>`, if the value attribute is missing.
389
- * Value and textContent can be interpolated.
390
- *
391
- * The {@link select.SelectController select controller} exposes utility functions that can be used
392
- * to manipulate the select's behavior.
393
- *
394
- * ## Matching model and option values
395
- *
396
- * In general, the match between the model and an option is evaluated by strictly comparing the model
397
- * value against the value of the available options.
398
- *
399
- * If you are setting the option value with the option's `value` attribute, or textContent, the
400
- * value will always be a `string` which means that the model value must also be a string.
401
- * Otherwise the `select` directive cannot match them correctly.
402
- *
403
- * To bind the model to a non-string value, you can use one of the following strategies:
404
- * - the {@link ng.ngOptions `ngOptions`} directive
405
- * ({@link ng.select#using-select-with-ngoptions-and-setting-a-default-value})
406
- * - the {@link ng.ngValue `ngValue`} directive, which allows arbitrary expressions to be
407
- * option values ({@link ng.select#using-ngvalue-to-bind-the-model-to-an-array-of-objects Example})
408
- * - model $parsers / $formatters to convert the string value
409
- * ({@link ng.select#binding-select-to-a-non-string-value-via-ngmodel-parsing-formatting Example})
410
- *
411
- * If the viewValue of `ngModel` does not match any of the options, then the control
412
- * will automatically add an "unknown" option, which it then removes when the mismatch is resolved.
413
- *
414
- * Optionally, a single hard-coded `<option>` element, with the value set to an empty string, can
415
- * be nested into the `<select>` element. This element will then represent the `null` or "not selected"
416
- * option. See example below for demonstration.
417
- *
418
- * ## Choosing between `ngRepeat` and `ngOptions`
419
- *
420
- * In many cases, `ngRepeat` can be used on `<option>` elements instead of {@link ng.directive:ngOptions
421
- * ngOptions} to achieve a similar result. However, `ngOptions` provides some benefits:
422
- * - more flexibility in how the `<select>`'s model is assigned via the `select` **`as`** part of the
423
- * comprehension expression
424
- * - reduced memory consumption by not creating a new scope for each repeated instance
425
- * - increased render speed by creating the options in a documentFragment instead of individually
426
- *
427
- * Specifically, select with repeated options slows down significantly starting at 2000 options in
428
- * Chrome and Internet Explorer / Edge.
429
- *
430
- *
431
- * @param {string} ngModel Assignable AngularJS expression to data-bind to.
432
- * @param {string=} name Property name of the form under which the control is published.
433
- * @param {string=} multiple Allows multiple options to be selected. The selected values will be
434
- * bound to the model as an array.
435
- * @param {string=} required Sets `required` validation error key if the value is not entered.
436
- * @param {string=} ngRequired Adds required attribute and required validation constraint to
437
- * the element when the ngRequired expression evaluates to true. Use ngRequired instead of required
438
- * when you want to data-bind to the required attribute.
439
- * @param {string=} ngChange AngularJS expression to be executed when selected option(s) changes due to user
440
- * interaction with the select element.
441
- * @param {string=} ngOptions sets the options that the select is populated with and defines what is
442
- * set on the model on selection. See {@link ngOptions `ngOptions`}.
443
- * @param {string=} ngAttrSize sets the size of the select element dynamically. Uses the
444
- * {@link guide/interpolation#-ngattr-for-binding-to-arbitrary-attributes ngAttr} directive.
445
- *
373
+ * @returns {import('../../types').Directive}
446
374
  */
447
- export const selectDirective = function () {
375
+ export function selectDirective() {
448
376
  return {
449
377
  restrict: "E",
450
378
  require: ["select", "?ngModel"],
@@ -567,54 +495,55 @@ export const selectDirective = function () {
567
495
  selectCtrl.writeValue(ngModelCtrl.$viewValue);
568
496
  };
569
497
  }
570
- };
498
+ }
571
499
 
572
500
  // The option directive is purely designed to communicate the existence (or lack of)
573
501
  // of dynamically created (and destroyed) option elements to their containing select
574
502
  // directive via its controller.
575
- export const optionDirective = [
576
- "$interpolate",
577
- function ($interpolate) {
578
- return {
579
- restrict: "E",
580
- priority: 100,
581
- compile(element, attr) {
582
- let interpolateValueFn;
583
- let interpolateTextFn;
584
-
585
- if (isDefined(attr.ngValue)) {
586
- // Will be handled by registerOption
587
- } else if (isDefined(attr.value)) {
588
- // If the value attribute is defined, check if it contains an interpolation
589
- interpolateValueFn = $interpolate(attr.value, true);
590
- } else {
591
- // If the value attribute is not defined then we fall back to the
592
- // text content of the option element, which may be interpolated
593
- interpolateTextFn = $interpolate(element.text(), true);
594
- if (!interpolateTextFn) {
595
- attr.$set("value", element.text());
596
- }
503
+ /**
504
+ * @returns {import('../../types').Directive}
505
+ */
506
+ optionDirective.$inject = ["$interpolate"];
507
+ export function optionDirective($interpolate) {
508
+ return {
509
+ restrict: "E",
510
+ priority: 100,
511
+ compile(element, attr) {
512
+ let interpolateValueFn;
513
+ let interpolateTextFn;
514
+
515
+ if (isDefined(attr.ngValue)) {
516
+ // Will be handled by registerOption
517
+ } else if (isDefined(attr.value)) {
518
+ // If the value attribute is defined, check if it contains an interpolation
519
+ interpolateValueFn = $interpolate(attr.value, true);
520
+ } else {
521
+ // If the value attribute is not defined then we fall back to the
522
+ // text content of the option element, which may be interpolated
523
+ interpolateTextFn = $interpolate(element.text(), true);
524
+ if (!interpolateTextFn) {
525
+ attr.$set("value", element.text());
597
526
  }
527
+ }
598
528
 
599
- return function (scope, element, attr) {
600
- // This is an optimization over using ^^ since we don't want to have to search
601
- // all the way to the root of the DOM for every single option element
602
- const selectCtrlName = "$selectController";
603
- const parent = element.parent();
604
- const selectCtrl =
605
- parent.data(selectCtrlName) || parent.parent().data(selectCtrlName); // in case we are in optgroup
606
-
607
- if (selectCtrl) {
608
- selectCtrl.registerOption(
609
- scope,
610
- element,
611
- attr,
612
- interpolateValueFn,
613
- interpolateTextFn,
614
- );
615
- }
616
- };
617
- },
618
- };
619
- },
620
- ];
529
+ return function (scope, element, attr) {
530
+ // This is an optimization over using ^^ since we don't want to have to search
531
+ // all the way to the root of the DOM for every single option element
532
+ const selectCtrlName = "$selectController";
533
+ const parent = element.parent();
534
+ const selectCtrl =
535
+ parent.data(selectCtrlName) || parent.parent().data(selectCtrlName); // in case we are in optgroup
536
+
537
+ if (selectCtrl) {
538
+ selectCtrl.registerOption(
539
+ scope,
540
+ element,
541
+ attr,
542
+ interpolateValueFn,
543
+ interpolateTextFn,
544
+ );
545
+ }
546
+ };
547
+ },
548
+ };
549
+ }
@@ -0,0 +1,74 @@
1
+ /\*\*
2
+
3
+ - @ngdoc directive
4
+ - @name select
5
+ - @restrict E
6
+ -
7
+ - @description
8
+ - HTML `select` element with AngularJS data-binding.
9
+ -
10
+ - The `select` directive is used together with {@link ngModel `ngModel`} to provide data-binding
11
+ - between the scope and the `<select>` control (including setting default values).
12
+ - It also handles dynamic `<option>` elements, which can be added using the {@link ngRepeat `ngRepeat}` or
13
+ - {@link ngOptions `ngOptions`} directives.
14
+ -
15
+ - When an item in the `<select>` menu is selected, the value of the selected option will be bound
16
+ - to the model identified by the `ngModel` directive. With static or repeated options, this is
17
+ - the content of the `value` attribute or the textContent of the `<option>`, if the value attribute is missing.
18
+ - Value and textContent can be interpolated.
19
+ -
20
+ - The {@link select.SelectController select controller} exposes utility functions that can be used
21
+ - to manipulate the select's behavior.
22
+ -
23
+ - ## Matching model and option values
24
+ -
25
+ - In general, the match between the model and an option is evaluated by strictly comparing the model
26
+ - value against the value of the available options.
27
+ -
28
+ - If you are setting the option value with the option's `value` attribute, or textContent, the
29
+ - value will always be a `string` which means that the model value must also be a string.
30
+ - Otherwise the `select` directive cannot match them correctly.
31
+ -
32
+ - To bind the model to a non-string value, you can use one of the following strategies:
33
+ - - the {@link ng.ngOptions `ngOptions`} directive
34
+ - ({@link ng.select#using-select-with-ngoptions-and-setting-a-default-value})
35
+ - - the {@link ng.ngValue `ngValue`} directive, which allows arbitrary expressions to be
36
+ - option values ({@link ng.select#using-ngvalue-to-bind-the-model-to-an-array-of-objects Example})
37
+ - - model $parsers / $formatters to convert the string value
38
+ - ({@link ng.select#binding-select-to-a-non-string-value-via-ngmodel-parsing-formatting Example})
39
+ -
40
+ - If the viewValue of `ngModel` does not match any of the options, then the control
41
+ - will automatically add an "unknown" option, which it then removes when the mismatch is resolved.
42
+ -
43
+ - Optionally, a single hard-coded `<option>` element, with the value set to an empty string, can
44
+ - be nested into the `<select>` element. This element will then represent the `null` or "not selected"
45
+ - option. See example below for demonstration.
46
+ -
47
+ - ## Choosing between `ngRepeat` and `ngOptions`
48
+ -
49
+ - In many cases, `ngRepeat` can be used on `<option>` elements instead of {@link ng.directive:ngOptions
50
+ - ngOptions} to achieve a similar result. However, `ngOptions` provides some benefits:
51
+ - - more flexibility in how the `<select>`'s model is assigned via the `select` **`as`** part of the
52
+ - comprehension expression
53
+ - - reduced memory consumption by not creating a new scope for each repeated instance
54
+ - - increased render speed by creating the options in a documentFragment instead of individually
55
+ -
56
+ - Specifically, select with repeated options slows down significantly starting at 2000 options in
57
+ - Chrome and Internet Explorer / Edge.
58
+ -
59
+ -
60
+ - @param {string} ngModel Assignable AngularJS expression to data-bind to.
61
+ - @param {string=} name Property name of the form under which the control is published.
62
+ - @param {string=} multiple Allows multiple options to be selected. The selected values will be
63
+ - bound to the model as an array.
64
+ - @param {string=} required Sets `required` validation error key if the value is not entered.
65
+ - @param {string=} ngRequired Adds required attribute and required validation constraint to
66
+ - the element when the ngRequired expression evaluates to true. Use ngRequired instead of required
67
+ - when you want to data-bind to the required attribute.
68
+ - @param {string=} ngChange AngularJS expression to be executed when selected option(s) changes due to user
69
+ - interaction with the select element.
70
+ - @param {string=} ngOptions sets the options that the select is populated with and defines what is
71
+ - set on the model on selection. See {@link ngOptions `ngOptions`}.
72
+ - @param {string=} ngAttrSize sets the size of the select element dynamically. Uses the
73
+ - {@link guide/interpolation#-ngattr-for-binding-to-arbitrary-attributes ngAttr} directive.
74
+ - \*/