@angular-wave/angular.ts 0.0.8 → 0.0.9

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.
@@ -0,0 +1,358 @@
1
+ /\*\*
2
+
3
+ - @ngdoc directive
4
+ - @name ngRepeat
5
+ - @multiElement
6
+ - @restrict A
7
+ -
8
+ - @description
9
+ - The `ngRepeat` directive instantiates a template once per item from a collection. Each template
10
+ - instance gets its own scope, where the given loop variable is set to the current collection item,
11
+ - and `$index` is set to the item index or key.
12
+ -
13
+ - Special properties are exposed on the local scope of each template instance, including:
14
+ -
15
+ - | Variable | Type | Details |
16
+ - |-----------|-----------------|-----------------------------------------------------------------------------|
17
+ - | `$index` | {@type number} | iterator offset of the repeated element (0..length-1) |
18
+ - | `$first` | {@type boolean} | true if the repeated element is first in the iterator. |
19
+ - | `$middle` | {@type boolean} | true if the repeated element is between the first and last in the iterator. |
20
+ - | `$last` | {@type boolean} | true if the repeated element is last in the iterator. |
21
+ - | `$even` | {@type boolean} | true if the iterator position `$index` is even (otherwise false). |
22
+ - | `$odd` | {@type boolean} | true if the iterator position `$index` is odd (otherwise false). |
23
+ -
24
+ - <div class="alert alert-info">
25
+ - Creating aliases for these properties is possible with {@link ng.directive:ngInit `ngInit`}.
26
+ - This may be useful when, for instance, nesting ngRepeats.
27
+ - </div>
28
+ -
29
+ -
30
+ - ## Iterating over object properties
31
+ -
32
+ - It is possible to get `ngRepeat` to iterate over the properties of an object using the following
33
+ - syntax:
34
+ -
35
+ - ```js
36
+
37
+ ```
38
+
39
+ - <div ng-repeat="(key, value) in myObj"> ... </div>
40
+ - ```
41
+
42
+ ```
43
+
44
+ -
45
+ - However, there are a few limitations compared to array iteration:
46
+ -
47
+ - - The JavaScript specification does not define the order of keys
48
+ - returned for an object, so AngularJS relies on the order returned by the browser
49
+ - when running `for key in myObj`. Browsers generally follow the strategy of providing
50
+ - keys in the order in which they were defined, although there are exceptions when keys are deleted
51
+ - and reinstated. See the
52
+ - [MDN page on `delete` for more info](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/delete#Cross-browser_notes).
53
+ -
54
+ - - `ngRepeat` will silently _ignore_ object keys starting with `$`, because
55
+ - it's a prefix used by AngularJS for public (`$`) and private (`$$`) properties.
56
+ -
57
+ - - The built-in filters {@link ng.orderBy orderBy} and {@link ng.filter filter} do not work with
58
+ - objects, and will throw an error if used with one.
59
+ -
60
+ - If you are hitting any of these limitations, the recommended workaround is to convert your object into an array
61
+ - that is sorted into the order that you prefer before providing it to `ngRepeat`. You could
62
+ - do this with a filter such as [toArrayFilter](http://ngmodules.org/modules/angular-toArrayFilter)
63
+ - or implement a `$watch` on the object yourself.
64
+ -
65
+ -
66
+ - ## Tracking and Duplicates
67
+ -
68
+ - `ngRepeat` uses {@link $rootScope.Scope#$watchCollection $watchCollection} to detect changes in
69
+ - the collection. When a change happens, `ngRepeat` then makes the corresponding changes to the DOM:
70
+ -
71
+ - - When an item is added, a new instance of the template is added to the DOM.
72
+ - - When an item is removed, its template instance is removed from the DOM.
73
+ - - When items are reordered, their respective templates are reordered in the DOM.
74
+ -
75
+ - To minimize creation of DOM elements, `ngRepeat` uses a function
76
+ - to "keep track" of all items in the collection and their corresponding DOM elements.
77
+ - For example, if an item is added to the collection, `ngRepeat` will know that all other items
78
+ - already have DOM elements, and will not re-render them.
79
+ -
80
+ - All different types of tracking functions, their syntax, and their support for duplicate
81
+ - items in collections can be found in the
82
+ - {@link ngRepeat#ngRepeat-arguments ngRepeat expression description}.
83
+ -
84
+ - <div class="alert alert-success">
85
+ - **Best Practice:** If you are working with objects that have a unique identifier property, you
86
+ - should track by this identifier instead of the object instance,
87
+ - e.g. `item in items track by item.id`.
88
+ - Should you reload your data later, `ngRepeat` will not have to rebuild the DOM elements for items
89
+ - it has already rendered, even if the JavaScript objects in the collection have been substituted
90
+ - for new ones. For large collections, this significantly improves rendering performance.
91
+ - </div>
92
+ -
93
+ - ### Effects of DOM Element re-use
94
+ -
95
+ - When DOM elements are re-used, ngRepeat updates the scope for the element, which will
96
+ - automatically update any active bindings on the template. However, other
97
+ - functionality will not be updated, because the element is not re-created:
98
+ -
99
+ - - Directives are not re-compiled
100
+ - - {@link guide/expression#one-time-binding one-time expressions} on the repeated template are not
101
+ - updated if they have stabilized.
102
+ -
103
+ - The above affects all kinds of element re-use due to tracking, but may be especially visible
104
+ - when tracking by `$index` due to the way ngRepeat re-uses elements.
105
+ -
106
+ - The following example shows the effects of different actions with tracking:
107
+
108
+ <example module="ngRepeat" name="ngRepeat-tracking" deps="angular-animate.js" animations="true">
109
+ <file name="script.js">
110
+ angular.module('ngRepeat', ['ngAnimate']).controller('repeatController', function($scope) {
111
+ let friends = [
112
+ {name:'John', age:25},
113
+ {name:'Mary', age:40},
114
+ {name:'Peter', age:85}
115
+ ];
116
+
117
+ $scope.removeFirst = function() {
118
+ $scope.friends.shift();
119
+ };
120
+
121
+ $scope.updateAge = function() {
122
+ $scope.friends.forEach(function(el) {
123
+ el.age = el.age + 5;
124
+ });
125
+ };
126
+
127
+ $scope.copy = function() {
128
+ $scope.friends = structuredClone($scope.friends);
129
+ };
130
+
131
+ $scope.reset = function() {
132
+ $scope.friends = structuredClone(friends);
133
+ };
134
+
135
+ $scope.reset();
136
+ });
137
+
138
+ </file>
139
+ <file name="index.html">
140
+ <div ng-controller="repeatController">
141
+ <ol>
142
+ <li>When you click "Update Age", only the first list updates the age, because all others have
143
+ a one-time binding on the age property. If you then click "Copy", the current friend list
144
+ is copied, and now the second list updates the age, because the identity of the collection items
145
+ has changed and the list must be re-rendered. The 3rd and 4th list stay the same, because all the
146
+ items are already known according to their tracking functions.
147
+ </li>
148
+ <li>When you click "Remove First", the 4th list has the wrong age on both remaining items. This is
149
+ due to tracking by $index: when the first collection item is removed, ngRepeat reuses the first
150
+ DOM element for the new first collection item, and so on. Since the age property is one-time
151
+ bound, the value remains from the collection item which was previously at this index.
152
+ </li>
153
+ </ol>
154
+
155
+ <button ng-click="removeFirst()">Remove First</button>
156
+ <button ng-click="updateAge()">Update Age</button>
157
+ <button ng-click="copy()">Copy</button>
158
+ <br><button ng-click="reset()">Reset List</button>
159
+ <br>
160
+ <code>track by $id(friend)</code> (default):
161
+ <ul class="example-animate-container">
162
+ <li class="animate-repeat" ng-repeat="friend in friends">
163
+ {{friend.name}} is {{friend.age}} years old.
164
+ </li>
165
+ </ul>
166
+ <code>track by $id(friend)</code> (default), with age one-time binding:
167
+ <ul class="example-animate-container">
168
+ <li class="animate-repeat" ng-repeat="friend in friends">
169
+ {{friend.name}} is {{::friend.age}} years old.
170
+ </li>
171
+ </ul>
172
+ <code>track by friend.name</code>, with age one-time binding:
173
+ <ul class="example-animate-container">
174
+ <li class="animate-repeat" ng-repeat="friend in friends track by friend.name">
175
+ {{friend.name}} is {{::friend.age}} years old.
176
+ </li>
177
+ </ul>
178
+ <code>track by $index</code>, with age one-time binding:
179
+ <ul class="example-animate-container">
180
+ <li class="animate-repeat" ng-repeat="friend in friends track by $index">
181
+ {{friend.name}} is {{::friend.age}} years old.
182
+ </li>
183
+ </ul>
184
+ </div>
185
+
186
+ </file>
187
+ <file name="animations.css">
188
+ .example-animate-container {
189
+ background:white;
190
+ border:1px solid black;
191
+ list-style:none;
192
+ margin:0;
193
+ padding:0 10px;
194
+ }
195
+
196
+ .animate-repeat {
197
+ line-height:30px;
198
+ list-style:none;
199
+ box-sizing:border-box;
200
+ }
201
+
202
+ .animate-repeat.ng-move,
203
+ .animate-repeat.ng-enter,
204
+ .animate-repeat.ng-leave {
205
+ transition:all linear 0.5s;
206
+ }
207
+
208
+ .animate-repeat.ng-leave.ng-leave-active,
209
+ .animate-repeat.ng-move,
210
+ .animate-repeat.ng-enter {
211
+ opacity:0;
212
+ max-height:0;
213
+ }
214
+
215
+ .animate-repeat.ng-leave,
216
+ .animate-repeat.ng-move.ng-move-active,
217
+ .animate-repeat.ng-enter.ng-enter-active {
218
+ opacity:1;
219
+ max-height:30px;
220
+ }
221
+
222
+ </file>
223
+
224
+ </example>
225
+
226
+ -
227
+ - ## Special repeat start and end points
228
+ - To repeat a series of elements instead of just one parent element, ngRepeat (as well as other ng directives) supports extending
229
+ - the range of the repeater by defining explicit start and end points by using **ng-repeat-start** and **ng-repeat-end** respectively.
230
+ - The **ng-repeat-start** directive works the same as **ng-repeat**, but will repeat all the HTML code (including the tag it's defined on)
231
+ - up to and including the ending HTML tag where **ng-repeat-end** is placed.
232
+ -
233
+ - The example below makes use of this feature:
234
+ - ```html
235
+
236
+ ```
237
+
238
+ - <header ng-repeat-start="item in items">
239
+ - Header {{ item }}
240
+ - </header>
241
+ - <div class="body">
242
+ - Body {{ item }}
243
+ - </div>
244
+ - <footer ng-repeat-end>
245
+ - Footer {{ item }}
246
+ - </footer>
247
+ - ```
248
+
249
+ ```
250
+
251
+ -
252
+ - And with an input of {@type ['A','B']} for the items variable in the example above, the output will evaluate to:
253
+ - ```html
254
+
255
+ ```
256
+
257
+ - <header>
258
+ - Header A
259
+ - </header>
260
+ - <div class="body">
261
+ - Body A
262
+ - </div>
263
+ - <footer>
264
+ - Footer A
265
+ - </footer>
266
+ - <header>
267
+ - Header B
268
+ - </header>
269
+ - <div class="body">
270
+ - Body B
271
+ - </div>
272
+ - <footer>
273
+ - Footer B
274
+ - </footer>
275
+ - ```
276
+
277
+ ```
278
+
279
+ -
280
+ - The custom start and end points for ngRepeat also support all other HTML directive syntax flavors provided in AngularJS (such
281
+ - as **data-ng-repeat-start**, **x-ng-repeat-start** and **ng:repeat-start**).
282
+ -
283
+ - @animations
284
+ - | Animation | Occurs |
285
+ - |----------------------------------|-------------------------------------|
286
+ - | {@link ng.$animate#enter enter} | when a new item is added to the list or when an item is revealed after a filter |
287
+ - | {@link ng.$animate#leave leave} | when an item is removed from the list or when an item is filtered out |
288
+ - | {@link ng.$animate#move move } | when an adjacent item is filtered out causing a reorder or when the item contents are reordered |
289
+ -
290
+ - See the example below for defining CSS animations with ngRepeat.
291
+ -
292
+ - @element ANY
293
+ - @scope
294
+ - @priority 1000
295
+ - @param {repeat_expression} ngRepeat The expression indicating how to enumerate a collection. These
296
+ - formats are currently supported:
297
+ -
298
+ - - `variable in expression` – where variable is the user defined loop variable and `expression`
299
+ - is a scope expression giving the collection to enumerate.
300
+ -
301
+ - For example: `album in artist.albums`.
302
+ -
303
+ - - `(key, value) in expression` – where `key` and `value` can be any user defined identifiers,
304
+ - and `expression` is the scope expression giving the collection to enumerate.
305
+ -
306
+ - For example: `(name, age) in {'adam':10, 'amalie':12}`.
307
+ -
308
+ - - `variable in expression track by tracking_expression` – You can also provide an optional tracking expression
309
+ - which can be used to associate the objects in the collection with the DOM elements. If no tracking expression
310
+ - is specified, ng-repeat associates elements by identity. It is an error to have
311
+ - more than one tracking expression value resolve to the same key. (This would mean that two distinct objects are
312
+ - mapped to the same DOM element, which is not possible.)
313
+ -
314
+ - *Default tracking: $id()*: `item in items` is equivalent to `item in items track by $id(item)`.
315
+ - This implies that the DOM elements will be associated by item identity in the collection.
316
+ -
317
+ - The built-in `$id()` function can be used to assign a unique
318
+ - `$$hashKey` property to each item in the collection. This property is then used as a key to associated DOM elements
319
+ - with the corresponding item in the collection by identity. Moving the same object would move
320
+ - the DOM element in the same way in the DOM.
321
+ - Note that the default id function does not support duplicate primitive values (`number`, `string`),
322
+ - but supports duplictae non-primitive values (`object`) that are *equal* in shape.
323
+ -
324
+ - *Custom Expression*: It is possible to use any AngularJS expression to compute the tracking
325
+ - id, for example with a function, or using a property on the collection items.
326
+ - `item in items track by item.id` is a typical pattern when the items have a unique identifier,
327
+ - e.g. database id. In this case the object identity does not matter. Two objects are considered
328
+ - equivalent as long as their `id` property is same.
329
+ - Tracking by unique identifier is the most performant way and should be used whenever possible.
330
+ -
331
+ - *$index*: This special property tracks the collection items by their index, and
332
+ - re-uses the DOM elements that match that index, e.g. `item in items track by $index`. This can
333
+ - be used for a performance improvement if no unique identfier is available and the identity of
334
+ - the collection items cannot be easily computed. It also allows duplicates.
335
+ -
336
+ - <div class="alert alert-warning">
337
+ - <strong>Note:</strong> Re-using DOM elements can have unforeseen effects. Read the
338
+ - {@link ngRepeat#tracking-and-duplicates section on tracking and duplicates} for
339
+ - more info.
340
+ - </div>
341
+ -
342
+ - <div class="alert alert-warning">
343
+ - <strong>Note:</strong> the `track by` expression must come last - after any filters, and the alias expression:
344
+ - `item in items | filter:searchText as results track by item.id`
345
+ - </div>
346
+ -
347
+ - - `variable in expression as alias_expression` – You can also provide an optional alias expression which will then store the
348
+ - intermediate results of the repeater after the filters have been applied. Typically this is used to render a special message
349
+ - when a filter is active on the repeater, but the filtered result set is empty.
350
+ -
351
+ - For example: `item in items | filter:x as results` will store the fragment of the repeated items as `results`, but only after
352
+ - the items have been processed through the filter.
353
+ -
354
+ - Please note that `as [variable name]` is not an operator but rather a part of ngRepeat
355
+ - micro-syntax so it can be used only after all filters (and not as operator, inside an expression).
356
+ -
357
+ - For example: `item in items | filter : x | orderBy : order | limitTo : limit as results track by item.id` .
358
+ - \*/
@@ -3,8 +3,7 @@ import { getBlockNodes } from "../jqLite";
3
3
 
4
4
  export const ngSwitchDirective = [
5
5
  "$animate",
6
- "$compile",
7
- ($animate, $compile) => ({
6
+ ($animate) => ({
8
7
  require: "ngSwitch",
9
8
 
10
9
  // asks for $scope to fool the BC controller module
@@ -58,8 +57,7 @@ export const ngSwitchDirective = [
58
57
  selectedTransclude.transclude((caseElement, selectedScope) => {
59
58
  selectedScopes.push(selectedScope);
60
59
  const anchor = selectedTransclude.element;
61
- caseElement[caseElement.length++] =
62
- $compile.$$createComment("end ngSwitchWhen");
60
+ caseElement[caseElement.length++] = document.createComment("");
63
61
  const block = { clone: caseElement };
64
62
 
65
63
  selectedElements.push(block);