@angular-wave/angular.ts 0.0.1 → 0.0.2

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 (70) hide show
  1. package/Makefile +1 -1
  2. package/dist/angular-ts.cjs.js +503 -1686
  3. package/dist/angular-ts.esm.js +503 -1686
  4. package/dist/angular-ts.umd.js +503 -1686
  5. package/package.json +1 -1
  6. package/src/animations/{animateCss.js → animate-css.js} +0 -1
  7. package/src/animations/animation.js +428 -431
  8. package/src/animations/module.js +9 -9
  9. package/src/core/compile.js +4 -1101
  10. package/src/core/compile.md +1192 -0
  11. package/src/core/location.js +1 -1
  12. package/src/core/utils.js +1 -1
  13. package/src/directive/a.js +1 -1
  14. package/src/directive/attrs.js +1 -1
  15. package/src/directive/csp.md +87 -0
  16. package/src/directive/input.js +3 -3
  17. package/src/directive/{ngModel.js → model.js} +1 -1
  18. package/src/directive/select.js +5 -5
  19. package/src/jqLite.js +0 -12
  20. package/src/public.js +24 -24
  21. package/src/services/log.js +66 -116
  22. package/src/services/log.md +39 -0
  23. package/test/jqlite.spec.js +0 -31
  24. package/test/messages/messages.spec.js +1 -1
  25. package/test/ng/compile.spec.js +13 -13
  26. package/test/ng/directive/model-options.spec.js +1 -1
  27. package/test/ng/directive/model.spec.js +1 -1
  28. package/test/ng/directive/options.spec.js +61 -61
  29. package/test/ng/directive/select.spec.js +22 -22
  30. package/test/ng/http-backend.spec.js +1 -1
  31. package/test/ng/on.spec.js +1 -1
  32. package/test/ng/prop.spec.js +54 -62
  33. package/test/ng/sanitize-uri.spec.js +1 -1
  34. package/test/ng/scope.spec.js +1 -1
  35. package/types/jqlite.d.ts +1 -32
  36. package/src/core/attributes.js +0 -199
  37. package/src/directive/ngCsp.js +0 -82
  38. /package/src/animations/{animateCache.js → animate-cache.js} +0 -0
  39. /package/src/animations/{animateChildrenDirective.js → animate-children-directive.js} +0 -0
  40. /package/src/animations/{animateCssDriver.js → animate-css-driver.js} +0 -0
  41. /package/src/animations/{animateJsDriver.js → animate-js-driver.js} +0 -0
  42. /package/src/animations/{animateJs.js → animate-js.js} +0 -0
  43. /package/src/animations/{animateQueue.js → animate-queue.js} +0 -0
  44. /package/src/animations/{ngAnimateSwap.js → animate-swap.js} +0 -0
  45. /package/src/animations/{rafScheduler.js → raf-scheduler.js} +0 -0
  46. /package/src/core/{animateCss.js → animate-css.js} +0 -0
  47. /package/src/core/{animateRunner.js → animate-runner.js} +0 -0
  48. /package/src/core/{exceptionHandler.js → exception-handler.js} +0 -0
  49. /package/src/core/{intervalFactory.js → interval-factory.js} +0 -0
  50. /package/src/core/{rootScope.js → root-scope.js} +0 -0
  51. /package/src/core/{sanitizeUri.js → sanitize-uri.js} +0 -0
  52. /package/src/core/{taskTrackerFactory.js → task-tracker-factory.js} +0 -0
  53. /package/src/directive/{ngClass.js → class.js} +0 -0
  54. /package/src/directive/{ngController.js → controller.js} +0 -0
  55. /package/src/directive/{ngIf.js → if.js} +0 -0
  56. /package/src/directive/{ngInclude.js → include.js} +0 -0
  57. /package/src/directive/{ngModelOptions.js → model-options.js} +0 -0
  58. /package/src/directive/{ngOptions.js → options.js} +0 -0
  59. /package/src/directive/{ngRef.js → ref.js} +0 -0
  60. /package/src/directive/{ngRepeat.js → repeat.js} +0 -0
  61. /package/src/directive/{ngShowHide.js → show-hide.js} +0 -0
  62. /package/src/directive/{ngSwitch.js → switch.js} +0 -0
  63. /package/src/directive/{ngTransclude.js → transclude.js} +0 -0
  64. /package/src/{routeToRegExp.js → route-to-reg-exp.js} +0 -0
  65. /package/src/services/{anchorScroll.js → anchor-scroll.js} +0 -0
  66. /package/src/services/{cacheFactory.js → cache-factory.js} +0 -0
  67. /package/src/services/{cookieReader.js → cookie-reader.js} +0 -0
  68. /package/src/services/{httpBackend.js → http-backend.js} +0 -0
  69. /package/src/services/{templateRequest.js → template-request.js} +0 -0
  70. /package/test/ng/{anomate.spec.js → animate.spec.js} +0 -0
@@ -0,0 +1,1192 @@
1
+ /\* ! VARIABLE/FUNCTION NAMING CONVENTIONS THAT APPLY TO THIS FILE!
2
+
3
+ -
4
+ - DOM-related variables:
5
+ -
6
+ - - "node" - DOM Node
7
+ - - "element" - DOM Element or Node
8
+ - - "$node" or "$element" - jqLite-wrapped node or element
9
+ -
10
+ -
11
+ - Compiler related stuff:
12
+ -
13
+ - - "linkFn" - linking fn of a single directive
14
+ - - "nodeLinkFn" - function that aggregates all linking fns for a particular node
15
+ - - "childLinkFn" - function that aggregates all linking fns for child nodes of a particular node
16
+ - - "compositeLinkFn" - function that aggregates all linking fns for a compilation root (nodeList)
17
+ \*/
18
+
19
+ /\*\*
20
+
21
+ - @ngdoc service
22
+ - @name $compile
23
+ - @kind function
24
+ -
25
+ - @description
26
+ - Compiles an HTML string or DOM into a template and produces a template function, which
27
+ - can then be used to link {@link ng.$rootScope.Scope `scope`} and the template together.
28
+ -
29
+ - The compilation is a process of walking the DOM tree and matching DOM elements to
30
+ - {@link ng.$compileProvider#directive directives}.
31
+ -
32
+ - <div class="alert alert-warning">
33
+ - **Note:** This document is an in-depth reference of all directive options.
34
+ - For a gentle introduction to directives with examples of common use cases,
35
+ - see the {@link guide/directive directive guide}.
36
+ - </div>
37
+ -
38
+ - ## Comprehensive Directive API
39
+ -
40
+ - There are many different options for a directive.
41
+ -
42
+ - The difference resides in the return value of the factory function.
43
+ - You can either return a {@link $compile#directive-definition-object Directive Definition Object (see below)}
44
+ - that defines the directive properties, or just the `postLink` function (all other properties will have
45
+ - the default values).
46
+ -
47
+ - <div class="alert alert-success">
48
+ - **Best Practice:** It's recommended to use the "directive definition object" form.
49
+ - </div>
50
+ -
51
+ - Here's an example directive declared with a Directive Definition Object:
52
+ -
53
+ - ```js
54
+
55
+ ```
56
+
57
+ - let myModule = angular.module(...);
58
+ -
59
+ - myModule.directive('directiveName', function factory(injectables) {
60
+ - let directiveDefinitionObject = {
61
+ - {@link $compile#-priority- priority}: 0,
62
+ - {@link $compile#-template- template}: '<div></div>', // or // function(tElement, tAttrs) { ... },
63
+ - // or
64
+ - // {@link $compile#-templateurl- templateUrl}: 'directive.html', // or // function(tElement, tAttrs) { ... },
65
+ - {@link $compile#-transclude- transclude}: false,
66
+ - {@link $compile#-restrict- restrict}: 'A',
67
+ - {@link $compile#-templatenamespace- templateNamespace}: 'html',
68
+ - {@link $compile#-scope- scope}: false,
69
+ - {@link $compile#-controller- controller}: function($scope, $element, $attrs, $transclude, otherInjectables) { ... },
70
+ - {@link $compile#-controlleras- controllerAs}: 'stringIdentifier',
71
+ - {@link $compile#-bindtocontroller- bindToController}: false,
72
+ - {@link $compile#-require- require}: 'siblingDirectiveName', // or // ['^parentDirectiveName', '?optionalDirectiveName', '?^optionalParent'],
73
+ - {@link $compile#-multielement- multiElement}: false,
74
+ - {@link $compile#-compile- compile}: function compile(tElement, tAttrs, transclude) {
75
+ - return {
76
+ - {@link $compile#pre-linking-function pre}: function preLink(scope, iElement, iAttrs, controller) { ... },
77
+ - {@link $compile#post-linking-function post}: function postLink(scope, iElement, iAttrs, controller) { ... }
78
+ - }
79
+ - // or
80
+ - // return function postLink( ... ) { ... }
81
+ - },
82
+ - // or
83
+ - // {@link $compile#-link- link}: {
84
+ - // {@link $compile#pre-linking-function pre}: function preLink(scope, iElement, iAttrs, controller) { ... },
85
+ - // {@link $compile#post-linking-function post}: function postLink(scope, iElement, iAttrs, controller) { ... }
86
+ - // }
87
+ - // or
88
+ - // {@link $compile#-link- link}: function postLink( ... ) { ... }
89
+ - };
90
+ - return directiveDefinitionObject;
91
+ - });
92
+ - ```
93
+
94
+ ```
95
+
96
+ -
97
+ - <div class="alert alert-warning">
98
+ - **Note:** Any unspecified options will use the default value. You can see the default values below.
99
+ - </div>
100
+ -
101
+ - Therefore the above can be simplified as:
102
+ -
103
+ - ```js
104
+
105
+ ```
106
+
107
+ - let myModule = angular.module(...);
108
+ -
109
+ - myModule.directive('directiveName', function factory(injectables) {
110
+ - let directiveDefinitionObject = {
111
+ - link: function postLink(scope, iElement, iAttrs) { ... }
112
+ - };
113
+ - return directiveDefinitionObject;
114
+ - // or
115
+ - // return function postLink(scope, iElement, iAttrs) { ... }
116
+ - });
117
+ - ```
118
+
119
+ ```
120
+
121
+ -
122
+ - ### Life-cycle hooks
123
+ - Directive controllers can provide the following methods that are called by AngularJS at points in the life-cycle of the
124
+ - directive:
125
+ - - `$onInit()` - Called on each controller after all the controllers on an element have been constructed and
126
+ - had their bindings initialized (and before the pre &amp; post linking functions for the directives on
127
+ - this element). This is a good place to put initialization code for your controller.
128
+ - - `$onChanges(changesObj)` - Called whenever one-way (`<`) or interpolation (`@`) bindings are updated. The
129
+ - `changesObj` is a hash whose keys are the names of the bound properties that have changed, and the values are an
130
+ - object of the form `{ currentValue, previousValue, isFirstChange() }`. Use this hook to trigger updates within a
131
+ - component such as cloning the bound value to prevent accidental mutation of the outer value. Note that this will
132
+ - also be called when your bindings are initialized.
133
+ - - `$doCheck()` - Called on each turn of the digest cycle. Provides an opportunity to detect and act on
134
+ - changes. Any actions that you wish to take in response to the changes that you detect must be
135
+ - invoked from this hook; implementing this has no effect on when `$onChanges` is called. For example, this hook
136
+ - could be useful if you wish to perform a deep equality check, or to check a Date object, changes to which would not
137
+ - be detected by AngularJS's change detector and thus not trigger `$onChanges`. This hook is invoked with no arguments;
138
+ - if detecting changes, you must store the previous value(s) for comparison to the current values.
139
+ - - `$onDestroy()` - Called on a controller when its containing scope is destroyed. Use this hook for releasing
140
+ - external resources, watches and event handlers. Note that components have their `$onDestroy()` hooks called in
141
+ - the same order as the `$scope.$broadcast` events are triggered, which is top down. This means that parent
142
+ - components will have their `$onDestroy()` hook called before child components.
143
+ - - `$postLink()` - Called after this controller's element and its children have been linked. Similar to the post-link
144
+ - function this hook can be used to set up DOM event handlers and do direct DOM manipulation.
145
+ - Note that child elements that contain `templateUrl` directives will not have been compiled and linked since
146
+ - they are waiting for their template to load asynchronously and their own compilation and linking has been
147
+ - suspended until that occurs.
148
+ -
149
+ - #### Comparison with life-cycle hooks in the new Angular
150
+ - The new Angular also uses life-cycle hooks for its components. While the AngularJS life-cycle hooks are similar there are
151
+ - some differences that you should be aware of, especially when it comes to moving your code from AngularJS to Angular:
152
+ -
153
+ - - AngularJS hooks are prefixed with `$`, such as `$onInit`. Angular hooks are prefixed with `ng`, such as `ngOnInit`.
154
+ - - AngularJS hooks can be defined on the controller prototype or added to the controller inside its constructor.
155
+ - In Angular you can only define hooks on the prototype of the Component class.
156
+ - - Due to the differences in change-detection, you may get many more calls to `$doCheck` in AngularJS than you would to
157
+ - `ngDoCheck` in Angular.
158
+ - - Changes to the model inside `$doCheck` will trigger new turns of the digest loop, which will cause the changes to be
159
+ - propagated throughout the application.
160
+ - Angular does not allow the `ngDoCheck` hook to trigger a change outside of the component. It will either throw an
161
+ - error or do nothing depending upon the state of `enableProdMode()`.
162
+ -
163
+ - #### Life-cycle hook examples
164
+ -
165
+ - This example shows how you can check for mutations to a Date object even though the identity of the object
166
+ - has not changed.
167
+ -
168
+ - <example name="doCheckDateExample" module="do-check-module">
169
+ - <file name="app.js">
170
+ - angular.module('do-check-module', [])
171
+ - .component('app', {
172
+ - template:
173
+ - 'Month: <input ng-model="$ctrl.month" ng-change="$ctrl.updateDate()">' +
174
+ - 'Date: {{ $ctrl.date }}' +
175
+ - '<test date="$ctrl.date"></test>',
176
+ - controller: function() {
177
+ - this.date = new Date();
178
+ - this.month = this.date.getMonth();
179
+ - this.updateDate = function() {
180
+ - this.date.setMonth(this.month);
181
+ - };
182
+ - }
183
+ - })
184
+ - .component('test', {
185
+ - bindings: { date: '<' },
186
+ - template:
187
+ - '<pre>{{ $ctrl.log | json }}</pre>',
188
+ - controller: function() {
189
+ - let previousValue;
190
+ - this.log = [];
191
+ - this.$doCheck = function() {
192
+ - let currentValue = this.date && this.date.valueOf();
193
+ - if (previousValue !== currentValue) {
194
+ - this.log.push('doCheck: date mutated: ' + this.date);
195
+ - previousValue = currentValue;
196
+ - }
197
+ - };
198
+ - }
199
+ - });
200
+ - </file>
201
+ - <file name="index.html">
202
+ - <app></app>
203
+ - </file>
204
+ - </example>
205
+ -
206
+ - This example show how you might use `$doCheck` to trigger changes in your component's inputs even if the
207
+ - actual identity of the component doesn't change. (Be aware that cloning and deep equality checks on large
208
+ - arrays or objects can have a negative impact on your application performance.)
209
+ -
210
+ - <example name="doCheckArrayExample" module="do-check-module">
211
+ - <file name="index.html">
212
+ - <div ng-init="items = []">
213
+ - <button ng-click="items.push(items.length)">Add Item</button>
214
+ - <button ng-click="items = []">Reset Items</button>
215
+ - <pre>{{ items }}</pre>
216
+ - <test items="items"></test>
217
+ - </div>
218
+ - </file>
219
+ - <file name="app.js">
220
+ - angular.module('do-check-module', [])
221
+ - .component('test', {
222
+ - bindings: { items: '<' },
223
+ - template:
224
+ - '<pre>{{ $ctrl.log | json }}</pre>',
225
+ - controller: function() {
226
+ - this.log = [];
227
+ -
228
+ - this.$doCheck = function() {
229
+ - if (this.items_ref !== this.items) {
230
+ - this.log.push('doCheck: items changed');
231
+ - this.items_ref = this.items;
232
+ - }
233
+ - if (!angular.equals(this.items_clone, this.items)) {
234
+ - this.log.push('doCheck: items mutated');
235
+ - this.items_clone = structuredClone(this.items);
236
+ - }
237
+ - };
238
+ - }
239
+ - });
240
+ - </file>
241
+ - </example>
242
+ -
243
+ -
244
+ - ### Directive Definition Object
245
+ -
246
+ - The directive definition object provides instructions to the {@link ng.$compile
247
+ - compiler}. The attributes are:
248
+ -
249
+ - #### `multiElement`
250
+ - When this property is set to true (default is `false`), the HTML compiler will collect DOM nodes between
251
+ - nodes with the attributes `directive-name-start` and `directive-name-end`, and group them
252
+ - together as the directive elements. It is recommended that this feature be used on directives
253
+ - which are not strictly behavioral (such as {@link ngClick}), and which
254
+ - do not manipulate or replace child nodes (such as {@link ngInclude}).
255
+ -
256
+ - #### `priority`
257
+ - When there are multiple directives defined on a single DOM element, sometimes it
258
+ - is necessary to specify the order in which the directives are applied. The `priority` is used
259
+ - to sort the directives before their `compile` functions get called. Priority is defined as a
260
+ - number. Directives with greater numerical `priority` are compiled first. Pre-link functions
261
+ - are also run in priority order, but post-link functions are run in reverse order. The order
262
+ - of directives with the same priority is undefined. The default priority is `0`.
263
+ -
264
+ - #### `terminal`
265
+ - If set to true then the current `priority` will be the last set of directives
266
+ - which will execute (any directives at the current priority will still execute
267
+ - as the order of execution on same `priority` is undefined). Note that expressions
268
+ - and other directives used in the directive's template will also be excluded from execution.
269
+ -
270
+ - #### `scope`
271
+ - The scope property can be `false`, `true`, or an object:
272
+ -
273
+ - - **`false` (default):** No scope will be created for the directive. The directive will use its
274
+ - parent's scope.
275
+ -
276
+ - - **`true`:** A new child scope that prototypically inherits from its parent will be created for
277
+ - the directive's element. If multiple directives on the same element request a new scope,
278
+ - only one new scope is created.
279
+ -
280
+ - - **`{...}` (an object hash):** A new "isolate" scope is created for the directive's template.
281
+ - The 'isolate' scope differs from normal scope in that it does not prototypically
282
+ - inherit from its parent scope. This is useful when creating reusable components, which should not
283
+ - accidentally read or modify data in the parent scope. Note that an isolate scope
284
+ - directive without a `template` or `templateUrl` will not apply the isolate scope
285
+ - to its children elements.
286
+ -
287
+ - The 'isolate' scope object hash defines a set of local scope properties derived from attributes on the
288
+ - directive's element. These local properties are useful for aliasing values for templates. The keys in
289
+ - the object hash map to the name of the property on the isolate scope; the values define how the property
290
+ - is bound to the parent scope, via matching attributes on the directive's element:
291
+ -
292
+ - - `@` or `@attr` - bind a local scope property to the value of DOM attribute. The result is
293
+ - always a string since DOM attributes are strings. If no `attr` name is specified then the
294
+ - attribute name is assumed to be the same as the local name. Given `<my-component
295
+ - my-attr="hello {{name}}">`and the isolate scope definition`scope: { localName:'@myAttr' }`,
296
+ - the directive's scope property `localName` will reflect the interpolated value of `hello
297
+ - {{name}}`. As the `name`attribute changes so will the`localName` property on the directive's
298
+ - scope. The `name` is read from the parent scope (not the directive's scope).
299
+ -
300
+ - - `=` or `=attr` - set up a bidirectional binding between a local scope property and an expression
301
+ - passed via the attribute `attr`. The expression is evaluated in the context of the parent scope.
302
+ - If no `attr` name is specified then the attribute name is assumed to be the same as the local
303
+ - name. Given `<my-component my-attr="parentModel">` and the isolate scope definition `scope: {
304
+ - localModel: '=myAttr' }`, the property `localModel` on the directive's scope will reflect the
305
+ - value of `parentModel` on the parent scope. Changes to `parentModel` will be reflected in
306
+ - `localModel` and vice versa. If the binding expression is non-assignable, or if the attribute
307
+ - isn't optional and doesn't exist, an exception
308
+ - ({@link error/$compile/nonassign `$compile:nonassign`}) will be thrown upon discovering changes
309
+ - to the local value, since it will be impossible to sync them back to the parent scope.
310
+ -
311
+ - By default, the {@link ng.$rootScope.Scope#$watch `$watch`}
312
+ - method is used for tracking changes, and the equality check is based on object identity.
313
+ - However, if an object literal or an array literal is passed as the binding expression, the
314
+ - equality check is done by value (using the {@link angular.equals} function). It's also possible
315
+ - to watch the evaluated value shallowly with {@link ng.$rootScope.Scope#$watchCollection
316
+ - `$watchCollection`}: use `=*` or `=*attr`
317
+ - - - `<` or `<attr` - set up a one-way (one-directional) binding between a local scope property and an
318
+ - expression passed via the attribute `attr`. The expression is evaluated in the context of the
319
+ - parent scope. If no `attr` name is specified then the attribute name is assumed to be the same as the
320
+ - local name.
321
+ -
322
+ - For example, given `<my-component my-attr="parentModel">` and directive definition of
323
+ - `scope: { localModel:'<myAttr' }`, then the isolated scope property `localModel` will reflect the
324
+ - value of `parentModel` on the parent scope. Any changes to `parentModel` will be reflected
325
+ - in `localModel`, but changes in `localModel` will not reflect in `parentModel`. There are however
326
+ - two caveats:
327
+ - 1. one-way binding does not copy the value from the parent to the isolate scope, it simply
328
+ - sets the same value. That means if your bound value is an object, changes to its properties
329
+ - in the isolated scope will be reflected in the parent scope (because both reference the same object).
330
+ - 2. one-way binding watches changes to the **identity** of the parent value. That means the
331
+ - {@link ng.$rootScope.Scope#$watch `$watch`} on the parent value only fires if the reference
332
+ - to the value has changed. In most cases, this should not be of concern, but can be important
333
+ - to know if you one-way bind to an object, and then replace that object in the isolated scope.
334
+ - If you now change a property of the object in your parent scope, the change will not be
335
+ - propagated to the isolated scope, because the identity of the object on the parent scope
336
+ - has not changed. Instead you must assign a new object.
337
+ -
338
+ - One-way binding is useful if you do not plan to propagate changes to your isolated scope bindings
339
+ - back to the parent. However, it does not make this completely impossible.
340
+ -
341
+ - By default, the {@link ng.$rootScope.Scope#$watch `$watch`}
342
+ - method is used for tracking changes, and the equality check is based on object identity.
343
+ - It's also possible to watch the evaluated value shallowly with
344
+ - {@link ng.$rootScope.Scope#$watchCollection `$watchCollection`}: use `<*` or `<*attr`
345
+ -
346
+ - - `&` or `&attr` - provides a way to execute an expression in the context of the parent scope. If
347
+ - no `attr` name is specified then the attribute name is assumed to be the same as the local name.
348
+ - Given `<my-component my-attr="count = count + value">` and the isolate scope definition `scope: {
349
+ - localFn:'&myAttr' }`, the isolate scope property `localFn` will point to a function wrapper for
350
+ - the `count = count + value` expression. Often it's desirable to pass data from the isolated scope
351
+ - via an expression to the parent scope. This can be done by passing a map of local variable names
352
+ - and values into the expression wrapper fn. For example, if the expression is `increment(amount)`
353
+ - then we can specify the amount value by calling the `localFn` as `localFn({amount: 22})`.
354
+ -
355
+ - All 4 kinds of bindings (`@`, `=`, `<`, and `&`) can be made optional by adding `?` to the expression.
356
+ - The marker must come after the mode and before the attribute name.
357
+ - See the {@link error/$compile/iscp Invalid Isolate Scope Definition error} for definition examples.
358
+ - This is useful to refine the interface directives provide.
359
+ - One subtle difference between optional and non-optional happens \*\*when the binding attribute is not
360
+ - set\*\*:
361
+ - - the binding is optional: the property will not be defined
362
+ - - the binding is not optional: the property is defined
363
+ -
364
+ - ````js
365
+ *app.directive('testDir', function() {
366
+ return {
367
+ scope: {
368
+ notoptional: '=',
369
+ optional: '=?',
370
+ },
371
+ bindToController: true,
372
+ controller: function() {
373
+ this.$onInit = function() {
374
+ console.log(this.hasOwnProperty('notoptional')) // true
375
+ console.log(this.hasOwnProperty('optional')) // false
376
+ }
377
+ }
378
+ }
379
+ })
380
+ *```
381
+ ````
382
+ -
383
+ -
384
+ - ##### Combining directives with different scope defintions
385
+ -
386
+ - In general it's possible to apply more than one directive to one element, but there might be limitations
387
+ - depending on the type of scope required by the directives. The following points will help explain these limitations.
388
+ - For simplicity only two directives are taken into account, but it is also applicable for several directives:
389
+ -
390
+ - - **no scope** + **no scope** => Two directives which don't require their own scope will use their parent's scope
391
+ - - **child scope** + **no scope** => Both directives will share one single child scope
392
+ - - **child scope** + **child scope** => Both directives will share one single child scope
393
+ - - **isolated scope** + **no scope** => The isolated directive will use it's own created isolated scope. The other directive will use
394
+ - its parent's scope
395
+ - - **isolated scope** + **child scope** => **Won't work!** Only one scope can be related to one element. Therefore these directives cannot
396
+ - be applied to the same element.
397
+ - - **isolated scope** + **isolated scope** => **Won't work!** Only one scope can be related to one element. Therefore these directives
398
+ - cannot be applied to the same element.
399
+ -
400
+ -
401
+ - #### `bindToController`
402
+ - This property is used to bind scope properties directly to the controller. It can be either
403
+ - `true` or an object hash with the same format as the `scope` property.
404
+ -
405
+ - When an isolate scope is used for a directive (see above), `bindToController: true` will
406
+ - allow a component to have its properties bound to the controller, rather than to scope.
407
+ -
408
+ - After the controller is instantiated, the initial values of the isolate scope bindings will be bound to the controller
409
+ - properties. You can access these bindings once they have been initialized by providing a controller method called
410
+ - `$onInit`, which is called after all the controllers on an element have been constructed and had their bindings
411
+ - initialized.
412
+ -
413
+ - It is also possible to set `bindToController` to an object hash with the same format as the `scope` property.
414
+ - This will set up the scope bindings to the controller directly. Note that `scope` can still be used
415
+ - to define which kind of scope is created. By default, no scope is created. Use `scope: {}` to create an isolate
416
+ - scope (useful for component directives).
417
+ -
418
+ - If both `bindToController` and `scope` are defined and have object hashes, `bindToController` overrides `scope`.
419
+ -
420
+ -
421
+ - #### `controller`
422
+ - Controller constructor function. The controller is instantiated before the
423
+ - pre-linking phase and can be accessed by other directives (see
424
+ - `require` attribute). This allows the directives to communicate with each other and augment
425
+ - each other's behavior. The controller is injectable (and supports bracket notation) with the following locals:
426
+ -
427
+ - - `$scope` - Current scope associated with the element
428
+ - - `$element` - Current element
429
+ - - `$attrs` - Current attributes object for the element
430
+ - - `$transclude` - A transclude linking function pre-bound to the correct transclusion scope:
431
+ - `function([scope], cloneLinkingFn, futureParentElement, slotName)`:
432
+ - - `scope`: (optional) override the scope.
433
+ - - `cloneLinkingFn`: (optional) argument to create clones of the original transcluded content.
434
+ - - `futureParentElement` (optional):
435
+ - * defines the parent to which the `cloneLinkingFn` will add the cloned elements.
436
+ - * default: `$element.parent()` resp. `$element` for `transclude:'element'` resp. `transclude:true`.
437
+ - * only needed for transcludes that are allowed to contain non html elements (e.g. SVG elements)
438
+ - and when the `cloneLinkingFn` is passed,
439
+ - as those elements need to created and cloned in a special way when they are defined outside their
440
+ - usual containers (e.g. like `<svg>`).
441
+ - * See also the `directive.templateNamespace` property.
442
+ - - `slotName`: (optional) the name of the slot to transclude. If falsy (e.g. `null`, `undefined` or `''`)
443
+ - then the default transclusion is provided.
444
+ - The `$transclude` function also has a method on it, `$transclude.isSlotFilled(slotName)`, which returns
445
+ - `true` if the specified slot contains content (i.e. one or more DOM nodes).
446
+ -
447
+ - #### `require`
448
+ - Require another directive and inject its controller as the fourth argument to the linking function. The
449
+ - `require` property can be a string, an array or an object:
450
+ - - a **string** containing the name of the directive to pass to the linking function
451
+ - - an **array** containing the names of directives to pass to the linking function. The argument passed to the
452
+ - linking function will be an array of controllers in the same order as the names in the `require` property
453
+ - - an **object** whose property values are the names of the directives to pass to the linking function. The argument
454
+ - passed to the linking function will also be an object with matching keys, whose values will hold the corresponding
455
+ - controllers.
456
+ -
457
+ - If the `require` property is an object and `bindToController` is truthy, then the required controllers are
458
+ - bound to the controller using the keys of the `require` property. This binding occurs after all the controllers
459
+ - have been constructed but before `$onInit` is called.
460
+ - If the name of the required controller is the same as the local name (the key), the name can be
461
+ - omitted. For example, `{parentDir: '^^'}` is equivalent to `{parentDir: '^^parentDir'}`.
462
+ - See the {@link $compileProvider#component} helper for an example of how this can be used.
463
+ - If no such required directive(s) can be found, or if the directive does not have a controller, then an error is
464
+ - raised (unless no link function is specified and the required controllers are not being bound to the directive
465
+ - controller, in which case error checking is skipped). The name can be prefixed with:
466
+ -
467
+ - - (no prefix) - Locate the required controller on the current element. Throw an error if not found.
468
+ - - `?` - Attempt to locate the required controller or pass `null` to the `link` fn if not found.
469
+ - - `^` - Locate the required controller by searching the element and its parents. Throw an error if not found.
470
+ - - `^^` - Locate the required controller by searching the element's parents. Throw an error if not found.
471
+ - - `?^` - Attempt to locate the required controller by searching the element and its parents or pass
472
+ - `null` to the `link` fn if not found.
473
+ - - `?^^` - Attempt to locate the required controller by searching the element's parents, or pass
474
+ - `null` to the `link` fn if not found.
475
+ -
476
+ -
477
+ - #### `controllerAs`
478
+ - Identifier name for a reference to the controller in the directive's scope.
479
+ - This allows the controller to be referenced from the directive template. This is especially
480
+ - useful when a directive is used as component, i.e. with an `isolate` scope. It's also possible
481
+ - to use it in a directive without an `isolate` / `new` scope, but you need to be aware that the
482
+ - `controllerAs` reference might overwrite a property that already exists on the parent scope.
483
+ -
484
+ -
485
+ - #### `restrict`
486
+ - String of subset of `EACM` which restricts the directive to a specific directive
487
+ - declaration style. If omitted, the defaults (elements and attributes) are used.
488
+ -
489
+ - - `E` - Element name (default): `<my-directive></my-directive>`
490
+ - - `A` - Attribute (default): `<div my-directive="exp"></div>`
491
+ - - `C` - Class: `<div class="my-directive: exp;"></div>`
492
+ - - `M` - Comment: `<!-- directive: my-directive exp -->`
493
+ -
494
+ -
495
+ - #### `templateNamespace`
496
+ - String representing the document type used by the markup in the template.
497
+ - AngularJS needs this information as those elements need to be created and cloned
498
+ - in a special way when they are defined outside their usual containers like `<svg>` and `<math>`.
499
+ -
500
+ - - `html` - All root nodes in the template are HTML. Root nodes may also be
501
+ - top-level elements such as `<svg>` or `<math>`.
502
+ - - `svg` - The root nodes in the template are SVG elements (excluding `<math>`).
503
+ - - `math` - The root nodes in the template are MathML elements (excluding `<svg>`).
504
+ -
505
+ - If no `templateNamespace` is specified, then the namespace is considered to be `html`.
506
+ -
507
+ - #### `template`
508
+ - HTML markup that may:
509
+ - - Replace the contents of the directive's element (default).
510
+ - - Replace the directive's element itself (if `replace` is true - DEPRECATED).
511
+ - - Wrap the contents of the directive's element (if `transclude` is true).
512
+ -
513
+ - Value may be:
514
+ -
515
+ - - A string. For example `<div red-on-hover>{{delete_str}}</div>`.
516
+ - - A function which takes two arguments `tElement` and `tAttrs` (described in the `compile`
517
+ - function api below) and returns a string value.
518
+ -
519
+ -
520
+ - #### `templateUrl`
521
+ - This is similar to `template` but the template is loaded from the specified URL, asynchronously.
522
+ -
523
+ - Because template loading is asynchronous the compiler will suspend compilation of directives on that element
524
+ - for later when the template has been resolved. In the meantime it will continue to compile and link
525
+ - sibling and parent elements as though this element had not contained any directives.
526
+ -
527
+ - The compiler does not suspend the entire compilation to wait for templates to be loaded because this
528
+ - would result in the whole app "stalling" until all templates are loaded asynchronously - even in the
529
+ - case when only one deeply nested directive has `templateUrl`.
530
+ -
531
+ - Template loading is asynchronous even if the template has been preloaded into the {@link $templateCache}.
532
+ -
533
+ - You can specify `templateUrl` as a string representing the URL or as a function which takes two
534
+ - arguments `tElement` and `tAttrs` (described in the `compile` function api below) and returns
535
+ - a string value representing the url. In either case, the template URL is passed through {@link
536
+ - $sce#getTrustedResourceUrl $sce.getTrustedResourceUrl}.
537
+ -
538
+ -
539
+ - #### `replace`
540
+ - <div class="alert alert-danger">
541
+ - **Note:** `replace` is deprecated in AngularJS and has been removed in the new Angular (v2+).
542
+ - </div>
543
+ -
544
+ - Specifies what the template should replace. Defaults to `false`.
545
+ -
546
+ - - `true` - the template will replace the directive's element.
547
+ - - `false` - the template will replace the contents of the directive's element.
548
+ -
549
+ - The replacement process migrates all of the attributes / classes from the old element to the new
550
+ - one. See the {@link guide/directive#template-expanding-directive
551
+ - Directives Guide} for an example.
552
+ -
553
+ - There are very few scenarios where element replacement is required for the application function,
554
+ - the main one being reusable custom components that are used within SVG contexts
555
+ - (because SVG doesn't work with custom elements in the DOM tree).
556
+ -
557
+ - #### `transclude`
558
+ - Extract the contents of the element where the directive appears and make it available to the directive.
559
+ - The contents are compiled and provided to the directive as a **transclusion function**. See the
560
+ - {@link $compile#transclusion Transclusion} section below.
561
+ -
562
+ -
563
+ - #### `compile`
564
+ -
565
+ - ```js
566
+
567
+ ```
568
+
569
+ - function compile(tElement, tAttrs, transclude) { ... }
570
+ - ```
571
+
572
+ ```
573
+
574
+ -
575
+ - The compile function deals with transforming the template DOM. Since most directives do not do
576
+ - template transformation, it is not used often. The compile function takes the following arguments:
577
+ -
578
+ - - `tElement` - template element - The element where the directive has been declared. It is
579
+ - safe to do template transformation on the element and child elements only.
580
+ -
581
+ - - `tAttrs` - template attributes - Normalized list of attributes declared on this element shared
582
+ - between all directive compile functions.
583
+ -
584
+ - - `transclude` - [*DEPRECATED*!] A transclude linking function: `function(scope, cloneLinkingFn)`
585
+ -
586
+ - <div class="alert alert-warning">
587
+ - **Note:** The template instance and the link instance may be different objects if the template has
588
+ - been cloned. For this reason it is **not** safe to do anything other than DOM transformations that
589
+ - apply to all cloned DOM nodes within the compile function. Specifically, DOM listener registration
590
+ - should be done in a linking function rather than in a compile function.
591
+ - </div>
592
+
593
+ - <div class="alert alert-warning">
594
+ - **Note:** The compile function cannot handle directives that recursively use themselves in their
595
+ - own templates or compile functions. Compiling these directives results in an infinite loop and
596
+ - stack overflow errors.
597
+ -
598
+ - This can be avoided by manually using `$compile` in the postLink function to imperatively compile
599
+ - a directive's template instead of relying on automatic template compilation via `template` or
600
+ - `templateUrl` declaration or manual compilation inside the compile function.
601
+ - </div>
602
+ -
603
+ - <div class="alert alert-danger">
604
+ - **Note:** The `transclude` function that is passed to the compile function is deprecated, as it
605
+ - e.g. does not know about the right outer scope. Please use the transclude function that is passed
606
+ - to the link function instead.
607
+ - </div>
608
+
609
+ - A compile function can have a return value which can be either a function or an object.
610
+ -
611
+ - - returning a (post-link) function - is equivalent to registering the linking function via the
612
+ - `link` property of the config object when the compile function is empty.
613
+ -
614
+ - - returning an object with function(s) registered via `pre` and `post` properties - allows you to
615
+ - control when a linking function should be called during the linking phase. See info about
616
+ - pre-linking and post-linking functions below.
617
+ -
618
+ -
619
+ - #### `link`
620
+ - This property is used only if the `compile` property is not defined.
621
+ -
622
+ - ```js
623
+
624
+ ```
625
+
626
+ - function link(scope, iElement, iAttrs, controller, transcludeFn) { ... }
627
+ - ```
628
+
629
+ ```
630
+
631
+ -
632
+ - The link function is responsible for registering DOM listeners as well as updating the DOM. It is
633
+ - executed after the template has been cloned. This is where most of the directive logic will be
634
+ - put.
635
+ -
636
+ - - `scope` - {@link ng.$rootScope.Scope Scope} - The scope to be used by the
637
+ - directive for registering {@link ng.$rootScope.Scope#$watch watches}.
638
+ -
639
+ - - `iElement` - instance element - The element where the directive is to be used. It is safe to
640
+ - manipulate the children of the element only in `postLink` function since the children have
641
+ - already been linked.
642
+ -
643
+ - - `iAttrs` - instance attributes - Normalized list of attributes declared on this element shared
644
+ - between all directive linking functions.
645
+ -
646
+ - - `controller` - the directive's required controller instance(s) - Instances are shared
647
+ - among all directives, which allows the directives to use the controllers as a communication
648
+ - channel. The exact value depends on the directive's `require` property:
649
+ - * no controller(s) required: the directive's own controller, or `undefined` if it doesn't have one
650
+ - * `string`: the controller instance
651
+ - * `array`: array of controller instances
652
+ -
653
+ - If a required controller cannot be found, and it is optional, the instance is `null`,
654
+ - otherwise the {@link error:$compile:ctreq Missing Required Controller} error is thrown.
655
+ -
656
+ - Note that you can also require the directive's own controller - it will be made available like
657
+ - any other controller.
658
+ -
659
+ - - `transcludeFn` - A transclude linking function pre-bound to the correct transclusion scope.
660
+ - This is the same as the `$transclude` parameter of directive controllers,
661
+ - see {@link ng.$compile#-controller- the controller section for details}.
662
+ - `function([scope], cloneLinkingFn, futureParentElement)`.
663
+ -
664
+ - #### Pre-linking function
665
+ -
666
+ - Executed before the child elements are linked. Not safe to do DOM transformation since the
667
+ - compiler linking function will fail to locate the correct elements for linking.
668
+ -
669
+ - #### Post-linking function
670
+ -
671
+ - Executed after the child elements are linked.
672
+ -
673
+ - Note that child elements that contain `templateUrl` directives will not have been compiled
674
+ - and linked since they are waiting for their template to load asynchronously and their own
675
+ - compilation and linking has been suspended until that occurs.
676
+ -
677
+ - It is safe to do DOM transformation in the post-linking function on elements that are not waiting
678
+ - for their async templates to be resolved.
679
+ -
680
+ -
681
+ - ### Transclusion
682
+ -
683
+ - Transclusion is the process of extracting a collection of DOM elements from one part of the DOM and
684
+ - copying them to another part of the DOM, while maintaining their connection to the original AngularJS
685
+ - scope from where they were taken.
686
+ -
687
+ - Transclusion is used (often with {@link ngTransclude}) to insert the
688
+ - original contents of a directive's element into a specified place in the template of the directive.
689
+ - The benefit of transclusion, over simply moving the DOM elements manually, is that the transcluded
690
+ - content has access to the properties on the scope from which it was taken, even if the directive
691
+ - has isolated scope.
692
+ - See the {@link guide/directive#creating-a-directive-that-wraps-other-elements Directives Guide}.
693
+ -
694
+ - This makes it possible for the widget to have private state for its template, while the transcluded
695
+ - content has access to its originating scope.
696
+ -
697
+ - <div class="alert alert-warning">
698
+ - **Note:** When testing an element transclude directive you must not place the directive at the root of the
699
+ - DOM fragment that is being compiled. See {@link guide/unit-testing#testing-transclusion-directives
700
+ - Testing Transclusion Directives}.
701
+ - </div>
702
+ -
703
+ - There are three kinds of transclusion depending upon whether you want to transclude just the contents of the
704
+ - directive's element, the entire element or multiple parts of the element contents:
705
+ -
706
+ - - `true` - transclude the content (i.e. the child nodes) of the directive's element.
707
+ - - `'element'` - transclude the whole of the directive's element including any directives on this
708
+ - element that are defined at a lower priority than this directive. When used, the `template`
709
+ - property is ignored.
710
+ - - **`{...}` (an object hash):** - map elements of the content onto transclusion "slots" in the template.
711
+ -
712
+ - **Multi-slot transclusion** is declared by providing an object for the `transclude` property.
713
+ -
714
+ - This object is a map where the keys are the name of the slot to fill and the value is an element selector
715
+ - used to match the HTML to the slot. The element selector should be in normalized form (e.g. `myElement`)
716
+ - and will match the standard element variants (e.g. `my-element`, `my:element`, `data-my-element`, etc).
717
+ -
718
+ - For further information check out the guide on {@link guide/directive#matching-directives Matching Directives}.
719
+ -
720
+ - If the element selector is prefixed with a `?` then that slot is optional.
721
+ -
722
+ - For example, the transclude object `{ slotA: '?myCustomElement' }` maps `<my-custom-element>` elements to
723
+ - the `slotA` slot, which can be accessed via the `$transclude` function or via the {@link ngTransclude} directive.
724
+ -
725
+ - Slots that are not marked as optional (`?`) will trigger a compile time error if there are no matching elements
726
+ - in the transclude content. If you wish to know if an optional slot was filled with content, then you can call
727
+ - `$transclude.isSlotFilled(slotName)` on the transclude function passed to the directive's link function and
728
+ - injectable into the directive's controller.
729
+ -
730
+ -
731
+ - #### Transclusion Functions
732
+ -
733
+ - When a directive requests transclusion, the compiler extracts its contents and provides a \*\*transclusion
734
+ - function\*\* to the directive's `link` function and `controller`. This transclusion function is a special
735
+ - **linking function** that will return the compiled contents linked to a new transclusion scope.
736
+ -
737
+ - <div class="alert alert-info">
738
+ - If you are just using {@link ngTransclude} then you don't need to worry about this function, since
739
+ - ngTransclude will deal with it for us.
740
+ - </div>
741
+ -
742
+ - If you want to manually control the insertion and removal of the transcluded content in your directive
743
+ - then you must use this transclude function. When you call a transclude function it returns a jqLite/JQuery
744
+ - object that contains the compiled DOM, which is linked to the correct transclusion scope.
745
+ -
746
+ - When you call a transclusion function you can pass in a **clone attach function**. This function accepts
747
+ - two parameters, `function(clone, scope) { ... }`, where the `clone` is a fresh compiled copy of your transcluded
748
+ - content and the `scope` is the newly created transclusion scope, which the clone will be linked to.
749
+ -
750
+ - <div class="alert alert-info">
751
+ - **Best Practice**: Always provide a `cloneFn` (clone attach function) when you call a transclude function
752
+ - since you then get a fresh clone of the original DOM and also have access to the new transclusion scope.
753
+ - </div>
754
+ -
755
+ - It is normal practice to attach your transcluded content (`clone`) to the DOM inside your \*\*clone
756
+ - attach function\*\*:
757
+ -
758
+ - ```js
759
+
760
+ ```
761
+
762
+ - let transcludedContent, transclusionScope;
763
+ -
764
+ - $transclude(function(clone, scope) {
765
+ - element.append(clone);
766
+ - transcludedContent = clone;
767
+ - transclusionScope = scope;
768
+ - });
769
+ - ```
770
+
771
+ ```
772
+
773
+ -
774
+ - Later, if you want to remove the transcluded content from your DOM then you should also destroy the
775
+ - associated transclusion scope:
776
+ -
777
+ - ```js
778
+
779
+ ```
780
+
781
+ - transcludedContent.remove();
782
+ - transclusionScope.$destroy();
783
+ - ```
784
+
785
+ ```
786
+
787
+ -
788
+ - <div class="alert alert-info">
789
+ - **Best Practice**: if you intend to add and remove transcluded content manually in your directive
790
+ - (by calling the transclude function to get the DOM and calling `element.remove()` to remove it),
791
+ - then you are also responsible for calling `$destroy` on the transclusion scope.
792
+ - </div>
793
+ -
794
+ - The built-in DOM manipulation directives, such as {@link ngIf}, {@link ngSwitch} and {@link ngRepeat}
795
+ - automatically destroy their transcluded clones as necessary so you do not need to worry about this if
796
+ - you are simply using {@link ngTransclude} to inject the transclusion into your directive.
797
+ -
798
+ -
799
+ - #### Transclusion Scopes
800
+ -
801
+ - When you call a transclude function it returns a DOM fragment that is pre-bound to a \*\*transclusion
802
+ - scope\*\*. This scope is special, in that it is a child of the directive's scope (and so gets destroyed
803
+ - when the directive's scope gets destroyed) but it inherits the properties of the scope from which it
804
+ - was taken.
805
+ -
806
+ - For example consider a directive that uses transclusion and isolated scope. The DOM hierarchy might look
807
+ - like this:
808
+ -
809
+ - ```html
810
+
811
+ ```
812
+
813
+ - <div ng-app>
814
+ - <div isolate>
815
+ - <div transclusion>
816
+ - </div>
817
+ - </div>
818
+ - </div>
819
+ - ```
820
+
821
+ ```
822
+
823
+ -
824
+ - The `$parent` scope hierarchy will look like this:
825
+ - ```
826
+ - $rootScope
827
+ - isolate
828
+ - transclusion
829
+ ```
830
+ -
831
+ - but the scopes will inherit prototypically from different scopes to their `$parent`.
832
+ - ```
833
+ - $rootScope
834
+ - transclusion
835
+ - isolate
836
+ ```
837
+ -
838
+ -
839
+ - ### Attributes
840
+ -
841
+ - The {@link ng.$compile.directive.Attributes Attributes} object - passed as a parameter in the
842
+ - `link()` or `compile()` functions. It has a variety of uses.
843
+ -
844
+ - - _Accessing normalized attribute names:_ Directives like `ngBind` can be expressed in many ways:
845
+ - `ng:bind`, `data-ng-bind`, or `x-ng-bind`. The attributes object allows for normalized access
846
+ - to the attributes.
847
+ -
848
+ - - _Directive inter-communication:_ All directives share the same instance of the attributes
849
+ - object which allows the directives to use the attributes object as inter directive
850
+ - communication.
851
+ -
852
+ - - _Supports interpolation:_ Interpolation attributes are assigned to the attribute object
853
+ - allowing other directives to read the interpolated value.
854
+ -
855
+ - - _Observing interpolated attributes:_ Use `$observe` to observe the value changes of attributes
856
+ - that contain interpolation (e.g. `src="{{bar}}"`). Not only is this very efficient but it's also
857
+ - the only way to easily get the actual value because during the linking phase the interpolation
858
+ - hasn't been evaluated yet and so the value is at this time set to `undefined`.
859
+ -
860
+ - ```js
861
+
862
+ ```
863
+
864
+ - function linkingFn(scope, elm, attrs, ctrl) {
865
+ - // get the attribute value
866
+ - console.log(attrs.ngModel);
867
+ -
868
+ - // change the attribute
869
+ - attrs.$set('ngModel', 'new value');
870
+ -
871
+ - // observe changes to interpolated attribute
872
+ - attrs.$observe('ngModel', function(value) {
873
+ - console.log('ngModel has changed value to ' + value);
874
+ - });
875
+ - }
876
+ - ```
877
+
878
+ ```
879
+
880
+ -
881
+ -
882
+ -
883
+ - @param {string|Element} element Element or HTML string to compile into a template function.
884
+ - @param {function(angular.Scope, cloneAttachFn=)} transclude function available to directives - DEPRECATED.
885
+ -
886
+ - <div class="alert alert-danger">
887
+ - **Note:** Passing a `transclude` function to the $compile function is deprecated, as it
888
+ - e.g. will not use the right outer scope. Please pass the transclude function as a
889
+ - `parentBoundTranscludeFn` to the link function instead.
890
+ - </div>
891
+ -
892
+ - @param {number} maxPriority only apply directives lower than given priority (Only effects the
893
+ - root element(s), not their children)
894
+ - @returns {function(scope, cloneAttachFn=, options=)} a link function which is used to bind template
895
+ - (a DOM element/tree) to a scope. Where:
896
+ -
897
+ - - `scope` - A {@link ng.$rootScope.Scope Scope} to bind to.
898
+ - - `cloneAttachFn` - If `cloneAttachFn` is provided, then the link function will clone the
899
+ - `template` and call the `cloneAttachFn` function allowing the caller to attach the
900
+ - cloned elements to the DOM document at the appropriate place. The `cloneAttachFn` is
901
+ - called as: <br/> `cloneAttachFn(clonedElement, scope)` where:
902
+ -
903
+ - * `clonedElement` - is a clone of the original `element` passed into the compiler.
904
+ - * `scope` - is the current scope with which the linking function is working with.
905
+ -
906
+ - - `options` - An optional object hash with linking options. If `options` is provided, then the following
907
+ - keys may be used to control linking behavior:
908
+ -
909
+ - * `parentBoundTranscludeFn` - the transclude function made available to
910
+ - directives; if given, it will be passed through to the link functions of
911
+ - directives found in `element` during compilation.
912
+ - * `transcludeControllers` - an object hash with keys that map controller names
913
+ - to a hash with the key `instance`, which maps to the controller instance;
914
+ - if given, it will make the controllers available to directives on the compileNode:
915
+ - ```
916
+ - {
917
+ - parent: {
918
+ - instance: parentControllerInstance
919
+ - }
920
+ - }
921
+ - ```
922
+ - * `futureParentElement` - defines the parent to which the `cloneAttachFn` will add
923
+ - the cloned elements; only needed for transcludes that are allowed to contain non HTML
924
+ - elements (e.g. SVG elements). See also the `directive.controller` property.
925
+ -
926
+ - Calling the linking function returns the element of the template. It is either the original
927
+ - element passed in, or the clone of the element if the `cloneAttachFn` is provided.
928
+ -
929
+ - After linking the view is not updated until after a call to `$digest`, which typically is done by
930
+ - AngularJS automatically.
931
+ -
932
+ - If you need access to the bound view, there are two ways to do it:
933
+ -
934
+ - - If you are not asking the linking function to clone the template, create the DOM element(s)
935
+ - before you send them to the compiler and keep this reference around.
936
+ - ```js
937
+
938
+ ```
939
+
940
+ - let element = angular.element('<p>{{total}}</p>');
941
+ - $compile(element)(scope);
942
+ - ```
943
+
944
+ ```
945
+
946
+ -
947
+ - - if on the other hand, you need the element to be cloned, the view reference from the original
948
+ - example would not point to the clone, but rather to the original template that was cloned. In
949
+ - this case, you can access the clone either via the `cloneAttachFn` or the value returned by the
950
+ - linking function:
951
+ - ```js
952
+
953
+ ```
954
+
955
+ - let templateElement = angular.element('<p>{{total}}</p>');
956
+ - let clonedElement = $compile(templateElement)(scope, function(clonedElement, scope) {
957
+ - // Attach the clone to DOM document at the right place.
958
+ - });
959
+ -
960
+ - // Now we have reference to the cloned DOM via `clonedElement`.
961
+ - // NOTE: The `clonedElement` returned by the linking function is the same as the
962
+ - // `clonedElement` passed to `cloneAttachFn`.
963
+ - ```
964
+
965
+ ```
966
+
967
+ -
968
+ -
969
+ - For information on how the compiler works, see the
970
+ - {@link guide/compiler AngularJS HTML Compiler} section of the Developer Guide.
971
+ -
972
+ - @knownIssue
973
+ -
974
+ - ### Double Compilation
975
+ - Double compilation occurs when an already compiled part of the DOM gets
976
+ compiled again. This is an undesired effect and can lead to misbehaving directives, performance issues,
977
+ and memory leaks. Refer to the Compiler Guide {@link guide/compiler#double-compilation-and-how-to-avoid-it
978
+ section on double compilation} for an in-depth explanation and ways to avoid it.
979
+
980
+ - @knownIssue
981
+
982
+ ### Issues with `replace: true`
983
+
984
+ -
985
+ - <div class="alert alert-danger">
986
+ - **Note**: {@link $compile#-replace- `replace: true`} is deprecated and not recommended to use,
987
+ - mainly due to the issues listed here. It has been completely removed in the new Angular.
988
+ - </div>
989
+ -
990
+ - #### Attribute values are not merged
991
+ -
992
+ - When a `replace` directive encounters the same attribute on the original and the replace node,
993
+ - it will simply deduplicate the attribute and join the values with a space or with a `;` in case of
994
+ - the `style` attribute.
995
+ - ```html
996
+
997
+ ```
998
+
999
+ - Original Node: <span class="original" style="color: red;"></span>
1000
+ - Replace Template: <span class="replaced" style="background: blue;"></span>
1001
+ - Result: <span class="original replaced" style="color: red; background: blue;"></span>
1002
+ - ```
1003
+
1004
+ ```
1005
+
1006
+ -
1007
+ - That means attributes that contain AngularJS expressions will not be merged correctly, e.g.
1008
+ - {@link ngShow} or {@link ngClass} will cause a {@link $parse} error:
1009
+ -
1010
+ - ```html
1011
+
1012
+ ```
1013
+
1014
+ - Original Node: <span ng-class="{'something': something}" ng-show="!condition"></span>
1015
+ - Replace Template: <span ng-class="{'else': else}" ng-show="otherCondition"></span>
1016
+ - Result: <span ng-class="{'something': something} {'else': else}" ng-show="!condition otherCondition"></span>
1017
+ - ```
1018
+
1019
+ ```
1020
+
1021
+ -
1022
+ - See issue [#5695](https://github.com/angular/angular.js/issues/5695).
1023
+ -
1024
+ - #### Directives are not deduplicated before compilation
1025
+ -
1026
+ - When the original node and the replace template declare the same directive(s), they will be
1027
+ - {@link guide/compiler#double-compilation-and-how-to-avoid-it compiled twice} because the compiler
1028
+ - does not deduplicate them. In many cases, this is not noticeable, but e.g. {@link ngModel} will
1029
+ - attach `$formatters` and `$parsers` twice.
1030
+ -
1031
+ - See issue [#2573](https://github.com/angular/angular.js/issues/2573).
1032
+ -
1033
+ - #### `transclude: element` in the replace template root can have unexpected effects
1034
+ -
1035
+ - When the replace template has a directive at the root node that uses
1036
+ - {@link $compile#-transclude- `transclude: element`}, e.g.
1037
+ - {@link ngIf} or {@link ngRepeat}, the DOM structure or scope inheritance can be incorrect.
1038
+ - See the following issues:
1039
+ -
1040
+ - - Incorrect scope on replaced element:
1041
+ - [#9837](https://github.com/angular/angular.js/issues/9837)
1042
+ - - Different DOM between `template` and `templateUrl`:
1043
+ - [#10612](https://github.com/angular/angular.js/issues/14326)
1044
+ - \*/
1045
+
1046
+ /\*\*
1047
+
1048
+ - @ngdoc directive
1049
+ - @name ngProp
1050
+ - @restrict A
1051
+ - @element ANY
1052
+ -
1053
+ - @usage
1054
+ -
1055
+ - ```html
1056
+
1057
+ ```
1058
+
1059
+ - <ANY ng-prop-propname="expression">
1060
+ - </ANY>
1061
+ - ```
1062
+
1063
+ ```
1064
+
1065
+ -
1066
+ - or with uppercase letters in property (e.g. "propName"):
1067
+ -
1068
+ -
1069
+ - ```html
1070
+
1071
+ ```
1072
+
1073
+ - <ANY ng-prop-prop_name="expression">
1074
+ - </ANY>
1075
+ - ```
1076
+
1077
+ ```
1078
+
1079
+ -
1080
+ -
1081
+ - @description
1082
+ - The `ngProp` directive binds an expression to a DOM element property.
1083
+ - `ngProp` allows writing to arbitrary properties by including
1084
+ - the property name in the attribute, e.g. `ng-prop-value="'my value'"` binds 'my value' to
1085
+ - the `value` property.
1086
+ -
1087
+ - Usually, it's not necessary to write to properties in AngularJS, as the built-in directives
1088
+ - handle the most common use cases (instead of the above example, you would use {@link ngValue}).
1089
+ -
1090
+ - However, [custom elements](https://developer.mozilla.org/docs/Web/Web_Components/Using_custom_elements)
1091
+ - often use custom properties to hold data, and `ngProp` can be used to provide input to these
1092
+ - custom elements.
1093
+ -
1094
+ - ## Binding to camelCase properties
1095
+ -
1096
+ - Since HTML attributes are case-insensitive, camelCase properties like `innerHTML` must be escaped.
1097
+ - AngularJS uses the underscore (\_) in front of a character to indicate that it is uppercase, so
1098
+ - `innerHTML` must be written as `ng-prop-inner_h_t_m_l="expression"` (Note that this is just an
1099
+ - example, and for binding HTML {@link ngBindHtml} should be used.
1100
+ -
1101
+ - ## Security
1102
+ -
1103
+ - Binding expressions to arbitrary properties poses a security risk, as properties like `innerHTML`
1104
+ - can insert potentially dangerous HTML into the application, e.g. script tags that execute
1105
+ - malicious code.
1106
+ - For this reason, `ngProp` applies Strict Contextual Escaping with the {@link ng.$sce $sce service}.
1107
+ - This means vulnerable properties require their content to be "trusted", based on the
1108
+ - context of the property. For example, the `innerHTML` is in the `HTML` context, and the
1109
+ - `iframe.src` property is in the `RESOURCE_URL` context, which requires that values written to
1110
+ - this property are trusted as a `RESOURCE_URL`.
1111
+ -
1112
+ - This can be set explicitly by calling $sce.trustAs(type, value) on the value that is
1113
+ - trusted before passing it to the `ng-prop-*` directive. There are exist shorthand methods for
1114
+ - each context type in the form of {@link ng.$sce#trustAsResourceUrl $sce.trustAsResourceUrl()} et al.
1115
+ -
1116
+ - In some cases you can also rely upon automatic sanitization of untrusted values - see below.
1117
+ -
1118
+ - Based on the context, other options may exist to mark a value as trusted / configure the behavior
1119
+ - of {@link ng.$sce}. For example, to restrict the `RESOURCE_URL` context to specific origins, use
1120
+ - the {@link $sceDelegateProvider#trustedResourceUrlList trustedResourceUrlList()}
1121
+ - and {@link $sceDelegateProvider#bannedResourceUrlList bannedResourceUrlList()}.
1122
+ -
1123
+ - {@link ng.$sce#what-trusted-context-types-are-supported- Find out more about the different context types}.
1124
+ -
1125
+ - ### HTML Sanitization
1126
+ -
1127
+ - By default, `$sce` will throw an error if it detects untrusted HTML content, and will not bind the
1128
+ - content.
1129
+ - However, if you include the {@link ngSanitize ngSanitize module}, it will try to sanitize the
1130
+ - potentially dangerous HTML, e.g. strip non-trusted tags and attributes when binding to
1131
+ - `innerHTML`.
1132
+ -
1133
+ - \*/
1134
+
1135
+ /\*\* @ngdoc directive
1136
+
1137
+ - @name ngOn
1138
+ - @restrict A
1139
+ - @element ANY
1140
+ -
1141
+ - @usage
1142
+ -
1143
+ - ```html
1144
+
1145
+ ```
1146
+
1147
+ - <ANY ng-on-eventname="expression">
1148
+ - </ANY>
1149
+ - ```
1150
+
1151
+ ```
1152
+
1153
+ -
1154
+ - or with uppercase letters in property (e.g. "eventName"):
1155
+ -
1156
+ -
1157
+ - ```html
1158
+
1159
+ ```
1160
+
1161
+ - <ANY ng-on-event_name="expression">
1162
+ - </ANY>
1163
+ - ```
1164
+
1165
+ ```
1166
+
1167
+ -
1168
+ - @description
1169
+ - The `ngOn` directive adds an event listener to a DOM element via
1170
+ - {@link angular.element angular.element().on()}, and evaluates an expression when the event is
1171
+ - fired.
1172
+ - `ngOn` allows adding listeners for arbitrary events by including
1173
+ - the event name in the attribute, e.g. `ng-on-drop="onDrop()"` executes the 'onDrop()' expression
1174
+ - when the `drop` event is fired.
1175
+ -
1176
+ - AngularJS provides specific directives for many events, such as {@link ngClick}, so in most
1177
+ - cases it is not necessary to use `ngOn`. However, AngularJS does not support all events
1178
+ - (e.g. the `drop` event in the example above), and new events might be introduced in later DOM
1179
+ - standards.
1180
+ -
1181
+ - Another use-case for `ngOn` is listening to
1182
+ - [custom events](https://developer.mozilla.org/docs/Web/Guide/Events/Creating_and_triggering_events)
1183
+ - fired by
1184
+ - [custom elements](https://developer.mozilla.org/docs/Web/Web_Components/Using_custom_elements).
1185
+ -
1186
+ - ## Binding to camelCase properties
1187
+ -
1188
+ - Since HTML attributes are case-insensitive, camelCase properties like `myEvent` must be escaped.
1189
+ - AngularJS uses the underscore (\_) in front of a character to indicate that it is uppercase, so
1190
+ - `myEvent` must be written as `ng-on-my_event="expression"`.
1191
+ -
1192
+ - \*/