@angular-wave/angular.ts 0.0.1
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.
- package/.eslintignore +1 -0
- package/.eslintrc.cjs +29 -0
- package/.github/workflows/playwright.yml +27 -0
- package/CHANGELOG.md +17974 -0
- package/CODE_OF_CONDUCT.md +3 -0
- package/CONTRIBUTING.md +246 -0
- package/DEVELOPERS.md +488 -0
- package/LICENSE +22 -0
- package/Makefile +31 -0
- package/README.md +115 -0
- package/RELEASE.md +98 -0
- package/SECURITY.md +16 -0
- package/TRIAGING.md +135 -0
- package/css/angular.css +22 -0
- package/dist/angular-ts.cjs.js +36843 -0
- package/dist/angular-ts.esm.js +36841 -0
- package/dist/angular-ts.umd.js +36848 -0
- package/dist/build/angular-animate.js +4272 -0
- package/dist/build/angular-aria.js +426 -0
- package/dist/build/angular-message-format.js +1072 -0
- package/dist/build/angular-messages.js +829 -0
- package/dist/build/angular-mocks.js +3757 -0
- package/dist/build/angular-parse-ext.js +1275 -0
- package/dist/build/angular-resource.js +911 -0
- package/dist/build/angular-route.js +1266 -0
- package/dist/build/angular-sanitize.js +891 -0
- package/dist/build/angular-touch.js +368 -0
- package/dist/build/angular.js +36600 -0
- package/e2e/unit.spec.ts +15 -0
- package/images/android-chrome-192x192.png +0 -0
- package/images/android-chrome-512x512.png +0 -0
- package/images/apple-touch-icon.png +0 -0
- package/images/favicon-16x16.png +0 -0
- package/images/favicon-32x32.png +0 -0
- package/images/favicon.ico +0 -0
- package/images/site.webmanifest +1 -0
- package/index.html +104 -0
- package/package.json +47 -0
- package/playwright.config.ts +78 -0
- package/public/circle.html +1 -0
- package/public/my_child_directive.html +1 -0
- package/public/my_directive.html +1 -0
- package/public/my_other_directive.html +1 -0
- package/public/test.html +1 -0
- package/rollup.config.js +31 -0
- package/src/animations/animateCache.js +55 -0
- package/src/animations/animateChildrenDirective.js +105 -0
- package/src/animations/animateCss.js +1139 -0
- package/src/animations/animateCssDriver.js +291 -0
- package/src/animations/animateJs.js +367 -0
- package/src/animations/animateJsDriver.js +67 -0
- package/src/animations/animateQueue.js +851 -0
- package/src/animations/animation.js +506 -0
- package/src/animations/module.js +779 -0
- package/src/animations/ngAnimateSwap.js +119 -0
- package/src/animations/rafScheduler.js +50 -0
- package/src/animations/shared.js +378 -0
- package/src/constants.js +20 -0
- package/src/core/animate.js +845 -0
- package/src/core/animateCss.js +73 -0
- package/src/core/animateRunner.js +195 -0
- package/src/core/attributes.js +199 -0
- package/src/core/cache.js +45 -0
- package/src/core/compile.js +4727 -0
- package/src/core/controller.js +225 -0
- package/src/core/exceptionHandler.js +63 -0
- package/src/core/filter.js +146 -0
- package/src/core/interpolate.js +442 -0
- package/src/core/interval.js +188 -0
- package/src/core/intervalFactory.js +57 -0
- package/src/core/location.js +1086 -0
- package/src/core/parser/parse.js +2562 -0
- package/src/core/parser/parse.md +13 -0
- package/src/core/q.js +746 -0
- package/src/core/rootScope.js +1596 -0
- package/src/core/sanitizeUri.js +85 -0
- package/src/core/sce.js +1161 -0
- package/src/core/taskTrackerFactory.js +125 -0
- package/src/core/timeout.js +121 -0
- package/src/core/urlUtils.js +187 -0
- package/src/core/utils.js +1349 -0
- package/src/directive/a.js +37 -0
- package/src/directive/attrs.js +283 -0
- package/src/directive/bind.js +51 -0
- package/src/directive/bind.md +142 -0
- package/src/directive/change.js +12 -0
- package/src/directive/change.md +25 -0
- package/src/directive/cloak.js +12 -0
- package/src/directive/cloak.md +24 -0
- package/src/directive/events.js +75 -0
- package/src/directive/events.md +166 -0
- package/src/directive/form.js +725 -0
- package/src/directive/init.js +15 -0
- package/src/directive/init.md +41 -0
- package/src/directive/input.js +1783 -0
- package/src/directive/list.js +46 -0
- package/src/directive/list.md +22 -0
- package/src/directive/ngClass.js +249 -0
- package/src/directive/ngController.js +64 -0
- package/src/directive/ngCsp.js +82 -0
- package/src/directive/ngIf.js +134 -0
- package/src/directive/ngInclude.js +217 -0
- package/src/directive/ngModel.js +1356 -0
- package/src/directive/ngModelOptions.js +509 -0
- package/src/directive/ngOptions.js +670 -0
- package/src/directive/ngRef.js +90 -0
- package/src/directive/ngRepeat.js +650 -0
- package/src/directive/ngShowHide.js +255 -0
- package/src/directive/ngSwitch.js +178 -0
- package/src/directive/ngTransclude.js +98 -0
- package/src/directive/non-bindable.js +11 -0
- package/src/directive/non-bindable.md +17 -0
- package/src/directive/script.js +30 -0
- package/src/directive/select.js +624 -0
- package/src/directive/style.js +25 -0
- package/src/directive/style.md +23 -0
- package/src/directive/validators.js +329 -0
- package/src/exts/aria.js +544 -0
- package/src/exts/messages.js +852 -0
- package/src/filters/filter.js +207 -0
- package/src/filters/filter.md +69 -0
- package/src/filters/filters.js +239 -0
- package/src/filters/json.md +16 -0
- package/src/filters/limit-to.js +43 -0
- package/src/filters/limit-to.md +19 -0
- package/src/filters/order-by.js +183 -0
- package/src/filters/order-by.md +83 -0
- package/src/index.js +13 -0
- package/src/injector.js +1034 -0
- package/src/jqLite.js +1117 -0
- package/src/loader.js +1320 -0
- package/src/public.js +215 -0
- package/src/routeToRegExp.js +41 -0
- package/src/services/anchorScroll.js +135 -0
- package/src/services/browser.js +321 -0
- package/src/services/cacheFactory.js +398 -0
- package/src/services/cookieReader.js +72 -0
- package/src/services/document.js +64 -0
- package/src/services/http.js +1537 -0
- package/src/services/httpBackend.js +206 -0
- package/src/services/log.js +160 -0
- package/src/services/templateRequest.js +139 -0
- package/test/angular.spec.js +2153 -0
- package/test/aria/aria.spec.js +1245 -0
- package/test/binding.spec.js +504 -0
- package/test/build-test.html +14 -0
- package/test/injector.spec.js +2327 -0
- package/test/jasmine/jasmine-5.1.2/boot0.js +65 -0
- package/test/jasmine/jasmine-5.1.2/boot1.js +133 -0
- package/test/jasmine/jasmine-5.1.2/jasmine-html.js +963 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.css +320 -0
- package/test/jasmine/jasmine-5.1.2/jasmine.js +10824 -0
- package/test/jasmine/jasmine-5.1.2/jasmine_favicon.png +0 -0
- package/test/jasmine/jasmine-browser.json +17 -0
- package/test/jasmine/jasmine.json +9 -0
- package/test/jqlite.spec.js +2133 -0
- package/test/loader.spec.js +219 -0
- package/test/messages/messages.spec.js +1146 -0
- package/test/min-err.spec.js +174 -0
- package/test/mock-test.html +13 -0
- package/test/module-test.html +15 -0
- package/test/ng/anomate.spec.js +606 -0
- package/test/ng/cache-factor.spec.js +334 -0
- package/test/ng/compile.spec.js +17956 -0
- package/test/ng/controller-provider.spec.js +227 -0
- package/test/ng/cookie-reader.spec.js +98 -0
- package/test/ng/directive/a.spec.js +192 -0
- package/test/ng/directive/bind.spec.js +334 -0
- package/test/ng/directive/boolean.spec.js +136 -0
- package/test/ng/directive/change.spec.js +71 -0
- package/test/ng/directive/class.spec.js +858 -0
- package/test/ng/directive/click.spec.js +38 -0
- package/test/ng/directive/cloak.spec.js +44 -0
- package/test/ng/directive/constoller.spec.js +194 -0
- package/test/ng/directive/element-style.spec.js +92 -0
- package/test/ng/directive/event.spec.js +282 -0
- package/test/ng/directive/form.spec.js +1518 -0
- package/test/ng/directive/href.spec.js +143 -0
- package/test/ng/directive/if.spec.js +402 -0
- package/test/ng/directive/include.spec.js +828 -0
- package/test/ng/directive/init.spec.js +68 -0
- package/test/ng/directive/input.spec.js +3810 -0
- package/test/ng/directive/list.spec.js +170 -0
- package/test/ng/directive/model-options.spec.js +1008 -0
- package/test/ng/directive/model.spec.js +1905 -0
- package/test/ng/directive/non-bindable.spec.js +55 -0
- package/test/ng/directive/options.spec.js +3583 -0
- package/test/ng/directive/ref.spec.js +575 -0
- package/test/ng/directive/repeat.spec.js +1675 -0
- package/test/ng/directive/script.spec.js +52 -0
- package/test/ng/directive/scrset.spec.js +67 -0
- package/test/ng/directive/select.spec.js +2541 -0
- package/test/ng/directive/show-hide.spec.js +253 -0
- package/test/ng/directive/src.spec.js +157 -0
- package/test/ng/directive/style.spec.js +178 -0
- package/test/ng/directive/switch.spec.js +647 -0
- package/test/ng/directive/validators.spec.js +717 -0
- package/test/ng/document.spec.js +52 -0
- package/test/ng/filter/filter.spec.js +714 -0
- package/test/ng/filter/filters.spec.js +35 -0
- package/test/ng/filter/limit-to.spec.js +251 -0
- package/test/ng/filter/order-by.spec.js +891 -0
- package/test/ng/filter.spec.js +149 -0
- package/test/ng/http-backend.spec.js +398 -0
- package/test/ng/http.spec.js +4071 -0
- package/test/ng/interpolate.spec.js +642 -0
- package/test/ng/interval.spec.js +343 -0
- package/test/ng/location.spec.js +3488 -0
- package/test/ng/on.spec.js +229 -0
- package/test/ng/parse.spec.js +4655 -0
- package/test/ng/prop.spec.js +805 -0
- package/test/ng/q.spec.js +2904 -0
- package/test/ng/root-element.spec.js +16 -0
- package/test/ng/sanitize-uri.spec.js +249 -0
- package/test/ng/sce.spec.js +660 -0
- package/test/ng/scope.spec.js +3442 -0
- package/test/ng/template-request.spec.js +236 -0
- package/test/ng/timeout.spec.js +351 -0
- package/test/ng/url-utils.spec.js +156 -0
- package/test/ng/utils.spec.js +144 -0
- package/test/original-test.html +21 -0
- package/test/public.spec.js +34 -0
- package/test/sanitize/bing-html.spec.js +36 -0
- package/test/server/express.js +158 -0
- package/test/test-utils.js +11 -0
- package/tsconfig.json +17 -0
- package/types/angular.d.ts +138 -0
- package/types/global.d.ts +9 -0
- package/types/index.d.ts +2357 -0
- package/types/jqlite.d.ts +558 -0
- package/vite.config.js +14 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @ngdoc directive
|
|
3
|
+
* @name a
|
|
4
|
+
* @restrict E
|
|
5
|
+
*
|
|
6
|
+
* @description
|
|
7
|
+
* Modifies the default behavior of the html a tag so that the default action is prevented when
|
|
8
|
+
* the href attribute is empty.
|
|
9
|
+
*
|
|
10
|
+
* For dynamically creating `href` attributes for a tags, see the {@link ng.ngHref `ngHref`} directive.
|
|
11
|
+
*/
|
|
12
|
+
export function htmlAnchorDirective() {
|
|
13
|
+
return {
|
|
14
|
+
restrict: "E",
|
|
15
|
+
compile: (_element, attr) => {
|
|
16
|
+
if (!attr.href && !attr.xlinkHref) {
|
|
17
|
+
return (_scope, element) => {
|
|
18
|
+
// If the linked element is not an anchor tag anymore, do nothing
|
|
19
|
+
if (element[0].nodeName.toLowerCase() !== "a") return;
|
|
20
|
+
|
|
21
|
+
// SVGAElement does not use the href attribute, but rather the 'xlinkHref' attribute.
|
|
22
|
+
const href =
|
|
23
|
+
toString.call(element.prop("href")) === "[object SVGAnimatedString]"
|
|
24
|
+
? "xlink:href"
|
|
25
|
+
: "href";
|
|
26
|
+
element.on("click", (event) => {
|
|
27
|
+
// if we have no href url, then don't navigate anywhere.
|
|
28
|
+
if (!element.attr(href)) {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
return () => {};
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { BOOLEAN_ATTR } from "../jqLite";
|
|
2
|
+
import { forEach, directiveNormalize } from "../core/utils";
|
|
3
|
+
import { ALIASED_ATTR } from "../constants";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @ngdoc directive
|
|
7
|
+
* @name ngHref
|
|
8
|
+
* @restrict A
|
|
9
|
+
* @priority 99
|
|
10
|
+
*
|
|
11
|
+
* @description
|
|
12
|
+
* Using AngularJS markup like `{{hash}}` in an href attribute will
|
|
13
|
+
* make the link go to the wrong URL if the user clicks it before
|
|
14
|
+
* AngularJS has a chance to replace the `{{hash}}` markup with its
|
|
15
|
+
* value. Until AngularJS replaces the markup the link will be broken
|
|
16
|
+
* and will most likely return a 404 error. The `ngHref` directive
|
|
17
|
+
* solves this problem.
|
|
18
|
+
*
|
|
19
|
+
* The wrong way to write it:
|
|
20
|
+
* ```html
|
|
21
|
+
* <a href="http://www.gravatar.com/avatar/{{hash}}">link1</a>
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* The correct way to write it:
|
|
25
|
+
* ```html
|
|
26
|
+
* <a ng-href="http://www.gravatar.com/avatar/{{hash}}">link1</a>
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* @element A
|
|
30
|
+
* @param {template} ngHref any string which can contain `{{}}` markup.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
export const REGEX_STRING_REGEXP = /^\/(.+)\/([a-z]*)$/;
|
|
35
|
+
/**
|
|
36
|
+
* @ngdoc directive
|
|
37
|
+
* @name ngSrc
|
|
38
|
+
* @restrict A
|
|
39
|
+
* @priority 99
|
|
40
|
+
*
|
|
41
|
+
* @description
|
|
42
|
+
* Using AngularJS markup like `{{hash}}` in a `src` attribute doesn't
|
|
43
|
+
* work right: The browser will fetch from the URL with the literal
|
|
44
|
+
* text `{{hash}}` until AngularJS replaces the expression inside
|
|
45
|
+
* `{{hash}}`. The `ngSrc` directive solves this problem.
|
|
46
|
+
*
|
|
47
|
+
* The buggy way to write it:
|
|
48
|
+
* ```html
|
|
49
|
+
* <img src="http://www.gravatar.com/avatar/{{hash}}" alt="Description"/>
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* The correct way to write it:
|
|
53
|
+
* ```html
|
|
54
|
+
* <img ng-src="http://www.gravatar.com/avatar/{{hash}}" alt="Description" />
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @element IMG
|
|
58
|
+
* @param {template} ngSrc any string which can contain `{{}}` markup.
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @ngdoc directive
|
|
63
|
+
* @name ngSrcset
|
|
64
|
+
* @restrict A
|
|
65
|
+
* @priority 99
|
|
66
|
+
*
|
|
67
|
+
* @description
|
|
68
|
+
* Using AngularJS markup like `{{hash}}` in a `srcset` attribute doesn't
|
|
69
|
+
* work right: The browser will fetch from the URL with the literal
|
|
70
|
+
* text `{{hash}}` until AngularJS replaces the expression inside
|
|
71
|
+
* `{{hash}}`. The `ngSrcset` directive solves this problem.
|
|
72
|
+
*
|
|
73
|
+
* The buggy way to write it:
|
|
74
|
+
* ```html
|
|
75
|
+
* <img srcset="http://www.gravatar.com/avatar/{{hash}} 2x" alt="Description"/>
|
|
76
|
+
* ```
|
|
77
|
+
*
|
|
78
|
+
* The correct way to write it:
|
|
79
|
+
* ```html
|
|
80
|
+
* <img ng-srcset="http://www.gravatar.com/avatar/{{hash}} 2x" alt="Description" />
|
|
81
|
+
* ```
|
|
82
|
+
*
|
|
83
|
+
* @element IMG
|
|
84
|
+
* @param {template} ngSrcset any string which can contain `{{}}` markup.
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @ngdoc directive
|
|
89
|
+
* @name ngDisabled
|
|
90
|
+
* @restrict A
|
|
91
|
+
* @priority 100
|
|
92
|
+
*
|
|
93
|
+
* @description
|
|
94
|
+
*
|
|
95
|
+
* This directive sets the `disabled` attribute on the element (typically a form control,
|
|
96
|
+
* e.g. `input`, `button`, `select` etc.) if the
|
|
97
|
+
* {@link guide/expression expression} inside `ngDisabled` evaluates to truthy.
|
|
98
|
+
*
|
|
99
|
+
* A special directive is necessary because we cannot use interpolation inside the `disabled`
|
|
100
|
+
* attribute. See the {@link guide/interpolation interpolation guide} for more info.
|
|
101
|
+
*
|
|
102
|
+
* @param {string} ngDisabled If the {@link guide/expression expression} is truthy,
|
|
103
|
+
* then the `disabled` attribute will be set on the element
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @ngdoc directive
|
|
108
|
+
* @name ngChecked
|
|
109
|
+
* @restrict A
|
|
110
|
+
* @priority 100
|
|
111
|
+
*
|
|
112
|
+
* @description
|
|
113
|
+
* Sets the `checked` attribute on the element, if the expression inside `ngChecked` is truthy.
|
|
114
|
+
*
|
|
115
|
+
* Note that this directive should not be used together with {@link ngModel `ngModel`},
|
|
116
|
+
* as this can lead to unexpected behavior.
|
|
117
|
+
*
|
|
118
|
+
* A special directive is necessary because we cannot use interpolation inside the `checked`
|
|
119
|
+
* attribute. See the {@link guide/interpolation interpolation guide} for more info.
|
|
120
|
+
*
|
|
121
|
+
* @element INPUT
|
|
122
|
+
* @param {string} ngChecked If the {@link guide/expression expression} is truthy,
|
|
123
|
+
* then the `checked` attribute will be set on the element
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
*
|
|
128
|
+
* @description
|
|
129
|
+
*
|
|
130
|
+
* Sets the `readonly` attribute on the element, if the expression inside `ngReadonly` is truthy.
|
|
131
|
+
* Note that `readonly` applies only to `input` elements with specific types. [See the input docs on
|
|
132
|
+
* MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-readonly) for more information.
|
|
133
|
+
*
|
|
134
|
+
* A special directive is necessary because we cannot use interpolation inside the `readonly`
|
|
135
|
+
* attribute. See the {@link guide/interpolation interpolation guide} for more info.
|
|
136
|
+
* @element INPUT
|
|
137
|
+
* @param {string} ngReadonly If the {@link guide/expression expression} is truthy,
|
|
138
|
+
* then special attribute "readonly" will be set on the element
|
|
139
|
+
*/
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @ngdoc directive
|
|
143
|
+
* @name ngSelected
|
|
144
|
+
* @restrict A
|
|
145
|
+
* @priority 100
|
|
146
|
+
*
|
|
147
|
+
* @description
|
|
148
|
+
*
|
|
149
|
+
* Sets the `selected` attribute on the element, if the expression inside `ngSelected` is truthy.
|
|
150
|
+
*
|
|
151
|
+
* A special directive is necessary because we cannot use interpolation inside the `selected`
|
|
152
|
+
* attribute. See the {@link guide/interpolation interpolation guide} for more info.
|
|
153
|
+
*
|
|
154
|
+
* <div class="alert alert-warning">
|
|
155
|
+
* **Note:** `ngSelected` does not interact with the `select` and `ngModel` directives, it only
|
|
156
|
+
* sets the `selected` attribute on the element. If you are using `ngModel` on the select, you
|
|
157
|
+
* should not use `ngSelected` on the options, as `ngModel` will set the select value and
|
|
158
|
+
* selected options.
|
|
159
|
+
* </div>
|
|
160
|
+
* @element OPTION
|
|
161
|
+
* @param {string} ngSelected If the {@link guide/expression expression} is truthy,
|
|
162
|
+
* then special attribute "selected" will be set on the element
|
|
163
|
+
*/
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @ngdoc directive
|
|
167
|
+
* @name ngOpen
|
|
168
|
+
* @restrict A
|
|
169
|
+
* @priority 100
|
|
170
|
+
*
|
|
171
|
+
* @description
|
|
172
|
+
*
|
|
173
|
+
* Sets the `open` attribute on the element, if the expression inside `ngOpen` is truthy.
|
|
174
|
+
*
|
|
175
|
+
* A special directive is necessary because we cannot use interpolation inside the `open`
|
|
176
|
+
* attribute. See the {@link guide/interpolation interpolation guide} for more info.
|
|
177
|
+
*
|
|
178
|
+
* ## A note about browser compatibility
|
|
179
|
+
*
|
|
180
|
+
* Internet Explorer and Edge do not support the `details` element, it is
|
|
181
|
+
* recommended to use {@link ng.ngShow} and {@link ng.ngHide} instead.
|
|
182
|
+
*
|
|
183
|
+
* @element DETAILS
|
|
184
|
+
* @param {string} ngOpen If the {@link guide/expression expression} is truthy,
|
|
185
|
+
* then special attribute "open" will be set on the element
|
|
186
|
+
*/
|
|
187
|
+
|
|
188
|
+
export const ngAttributeAliasDirectives = {};
|
|
189
|
+
|
|
190
|
+
// boolean attrs are evaluated
|
|
191
|
+
forEach(BOOLEAN_ATTR, (propName, attrName) => {
|
|
192
|
+
// binding to multiple is not supported
|
|
193
|
+
if (propName === "multiple") return;
|
|
194
|
+
|
|
195
|
+
function defaultLinkFn(scope, element, attr) {
|
|
196
|
+
scope.$watch(attr[normalized], (value) => {
|
|
197
|
+
attr.$set(attrName, !!value);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let normalized = directiveNormalize(`ng-${attrName}`);
|
|
202
|
+
let linkFn = defaultLinkFn;
|
|
203
|
+
|
|
204
|
+
if (propName === "checked") {
|
|
205
|
+
linkFn = function (scope, element, attr) {
|
|
206
|
+
// ensuring ngChecked doesn't interfere with ngModel when both are set on the same input
|
|
207
|
+
if (attr.ngModel !== attr[normalized]) {
|
|
208
|
+
defaultLinkFn(scope, element, attr);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
ngAttributeAliasDirectives[normalized] = function () {
|
|
214
|
+
return {
|
|
215
|
+
restrict: "A",
|
|
216
|
+
priority: 100,
|
|
217
|
+
link: linkFn,
|
|
218
|
+
};
|
|
219
|
+
};
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
// aliased input attrs are evaluated
|
|
223
|
+
forEach(ALIASED_ATTR, (htmlAttr, ngAttr) => {
|
|
224
|
+
ngAttributeAliasDirectives[ngAttr] = function () {
|
|
225
|
+
return {
|
|
226
|
+
priority: 100,
|
|
227
|
+
link(scope, element, attr) {
|
|
228
|
+
// special case ngPattern when a literal regular expression value
|
|
229
|
+
// is used as the expression (this way we don't have to watch anything).
|
|
230
|
+
if (ngAttr === "ngPattern" && attr.ngPattern.charAt(0) === "/") {
|
|
231
|
+
const match = attr.ngPattern.match(REGEX_STRING_REGEXP);
|
|
232
|
+
if (match) {
|
|
233
|
+
attr.$set("ngPattern", new RegExp(match[1], match[2]));
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
scope.$watch(attr[ngAttr], (value) => {
|
|
239
|
+
attr.$set(ngAttr, value);
|
|
240
|
+
});
|
|
241
|
+
},
|
|
242
|
+
};
|
|
243
|
+
};
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
// ng-src, ng-srcset, ng-href are interpolated
|
|
247
|
+
forEach(["src", "srcset", "href"], (attrName) => {
|
|
248
|
+
const normalized = directiveNormalize(`ng-${attrName}`);
|
|
249
|
+
ngAttributeAliasDirectives[normalized] = [
|
|
250
|
+
"$sce",
|
|
251
|
+
function ($sce) {
|
|
252
|
+
return {
|
|
253
|
+
priority: 99, // it needs to run after the attributes are interpolated
|
|
254
|
+
link(_scope, element, attr) {
|
|
255
|
+
let name = attrName;
|
|
256
|
+
|
|
257
|
+
if (
|
|
258
|
+
attrName === "href" &&
|
|
259
|
+
toString.call(element.prop("href")) === "[object SVGAnimatedString]"
|
|
260
|
+
) {
|
|
261
|
+
name = "xlinkHref";
|
|
262
|
+
attr.$attr[name] = "xlink:href";
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
// We need to sanitize the url at least once, in case it is a constant
|
|
266
|
+
// non-interpolated attribute.
|
|
267
|
+
attr.$set(normalized, $sce.getTrustedMediaUrl(attr[normalized]));
|
|
268
|
+
|
|
269
|
+
attr.$observe(normalized, (value) => {
|
|
270
|
+
if (!value) {
|
|
271
|
+
if (attrName === "href") {
|
|
272
|
+
attr.$set(name, null);
|
|
273
|
+
}
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
attr.$set(name, value);
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
},
|
|
282
|
+
];
|
|
283
|
+
});
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { isUndefined, stringify } from "../core/utils";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @returns {angular.IDirective}
|
|
5
|
+
*/
|
|
6
|
+
export function ngBindDirective() {
|
|
7
|
+
return {
|
|
8
|
+
restrict: "EA",
|
|
9
|
+
link: (scope, element, attr) => {
|
|
10
|
+
scope.$watch(attr.ngBind, (value) => {
|
|
11
|
+
element[0].textContent = stringify(value);
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @returns {angular.IDirective}
|
|
19
|
+
*/
|
|
20
|
+
export function ngBindTemplateDirective() {
|
|
21
|
+
return {
|
|
22
|
+
restrict: "EA",
|
|
23
|
+
link: (_scope, element, attr) => {
|
|
24
|
+
attr.$observe("ngBindTemplate", (value) => {
|
|
25
|
+
element[0].textContent = isUndefined(value) ? "" : value;
|
|
26
|
+
});
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* TODO: add type
|
|
33
|
+
*/
|
|
34
|
+
export const ngBindHtmlDirective = [
|
|
35
|
+
"$parse",
|
|
36
|
+
($parse) => {
|
|
37
|
+
return {
|
|
38
|
+
restrict: "A",
|
|
39
|
+
compile: (_tElement, tAttrs) => {
|
|
40
|
+
var ngBindHtmlGetter = $parse(tAttrs.ngBindHtml);
|
|
41
|
+
var ngBindHtmlWatch = $parse(tAttrs.ngBindHtml, (val) => val);
|
|
42
|
+
return (scope, element) => {
|
|
43
|
+
scope.$watch(ngBindHtmlWatch, () => {
|
|
44
|
+
// The watched value is the unwrapped value. To avoid re-escaping, use the direct getter.
|
|
45
|
+
element.html(ngBindHtmlGetter(scope) || "");
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
];
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
## ngBind Directive
|
|
2
|
+
|
|
3
|
+
### Description
|
|
4
|
+
|
|
5
|
+
The `ngBind` attribute tells AngularJS to replace the text content of the specified HTML element with the value of a given expression, and to update the text content when the value of that expression changes.
|
|
6
|
+
|
|
7
|
+
Typically, you don't use `ngBind` directly, but instead, you use the double curly markup like `{{ expression }}` which is similar but less verbose.
|
|
8
|
+
|
|
9
|
+
It is preferable to use `ngBind` instead of `{{ expression }}` if a template is momentarily displayed by the browser in its raw state before AngularJS compiles it. Since `ngBind` is an element attribute, it makes the bindings invisible to the user while the page is loading.
|
|
10
|
+
|
|
11
|
+
An alternative solution to this problem would be using the [`ngCloak`](https://docs.angularjs.org/api/ng/directive/ngCloak) directive.
|
|
12
|
+
|
|
13
|
+
### Element
|
|
14
|
+
|
|
15
|
+
ANY
|
|
16
|
+
|
|
17
|
+
### Parameter
|
|
18
|
+
|
|
19
|
+
- `ngBind`: [Expression](https://docs.angularjs.org/guide/expression) to evaluate.
|
|
20
|
+
|
|
21
|
+
### Example
|
|
22
|
+
|
|
23
|
+
Enter a name in the Live Preview text box; the greeting below the text box changes instantly.
|
|
24
|
+
|
|
25
|
+
```html
|
|
26
|
+
<example module="bindExample" name="ng-bind">
|
|
27
|
+
<file name="index.html">
|
|
28
|
+
<script>
|
|
29
|
+
angular.module("bindExample", []).controller("ExampleController", [
|
|
30
|
+
"$scope",
|
|
31
|
+
function ($scope) {
|
|
32
|
+
$scope.name = "Whirled";
|
|
33
|
+
},
|
|
34
|
+
]);
|
|
35
|
+
</script>
|
|
36
|
+
<div ng-controller="ExampleController">
|
|
37
|
+
<label>Enter name: <input type="text" ng-model="name" /></label><br />
|
|
38
|
+
Hello <span ng-bind="name"></span>!
|
|
39
|
+
</div>
|
|
40
|
+
</file>
|
|
41
|
+
<file name="protractor.js" type="protractor">
|
|
42
|
+
it('should check ng-bind', function() { var nameInput =
|
|
43
|
+
element(by.model('name'));
|
|
44
|
+
expect(element(by.binding('name')).getText()).toBe('Whirled');
|
|
45
|
+
nameInput.clear(); nameInput.sendKeys('world');
|
|
46
|
+
expect(element(by.binding('name')).getText()).toBe('world'); });
|
|
47
|
+
</file>
|
|
48
|
+
</example>
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## ngBindTemplate Directive
|
|
52
|
+
|
|
53
|
+
### Description
|
|
54
|
+
|
|
55
|
+
The `ngBindTemplate` directive specifies that the element text content should be replaced with the interpolation of the template in the `ngBindTemplate` attribute. Unlike `ngBind`, the `ngBindTemplate` can contain multiple `{{ }}` expressions. This directive is necessary since some HTML elements (such as `TITLE` and `OPTION`) cannot contain `SPAN` elements.
|
|
56
|
+
|
|
57
|
+
### Element
|
|
58
|
+
|
|
59
|
+
ANY
|
|
60
|
+
|
|
61
|
+
### Parameter
|
|
62
|
+
|
|
63
|
+
- `ngBindTemplate`: Template of form `{{ expression }}` to evaluate.
|
|
64
|
+
|
|
65
|
+
### Example
|
|
66
|
+
|
|
67
|
+
Try it here: enter text in the text box and watch the greeting change.
|
|
68
|
+
|
|
69
|
+
````html
|
|
70
|
+
<example module="bindExample" name="ng-bind-template">
|
|
71
|
+
<file name="index.html">
|
|
72
|
+
<script>
|
|
73
|
+
angular.module("bindExample", []).controller("ExampleController", [
|
|
74
|
+
"$scope",
|
|
75
|
+
function ($scope) {
|
|
76
|
+
$scope.salutation = "Hello";
|
|
77
|
+
$scope.name = "World";
|
|
78
|
+
},
|
|
79
|
+
]);
|
|
80
|
+
</script>
|
|
81
|
+
<div ng-controller="ExampleController">
|
|
82
|
+
<label>Salutation: <input type="text" ng-model="salutation" /></label
|
|
83
|
+
><br />
|
|
84
|
+
<label>Name: <input type="text" ng-model="name" /></label><br />
|
|
85
|
+
<pre ng-bind-template="{{salutation}} {{name}}!"></pre>
|
|
86
|
+
</div>
|
|
87
|
+
</file>
|
|
88
|
+
<file name="protractor.js" type="protractor">
|
|
89
|
+
it('should check ng-bind', function() { var salutationElem =
|
|
90
|
+
element(by.binding('salutation')); var salutationInput =
|
|
91
|
+
element(by.model('salutation')); var nameInput = element(by.model('name'));
|
|
92
|
+
expect(salutationElem.getText()).toBe('Hello World!');
|
|
93
|
+
salutationInput.clear(); salutationInput.sendKeys('Greetings');
|
|
94
|
+
nameInput.clear(); nameInput.sendKeys('user');
|
|
95
|
+
expect(salutationElem.getText()).toBe('Greetings user!'); });
|
|
96
|
+
</file>
|
|
97
|
+
</example>
|
|
98
|
+
|
|
99
|
+
## ngBindHtml Directive ### Description Evaluates the expression and inserts the
|
|
100
|
+
resulting HTML into the element in a secure way. By default, the resulting HTML
|
|
101
|
+
content will be sanitized using the
|
|
102
|
+
[`$sanitize`](https://docs.angularjs.org/api/ngSanitize/service/$sanitize)
|
|
103
|
+
service. To utilize this functionality, ensure that `$sanitize` is available,
|
|
104
|
+
for example, by including
|
|
105
|
+
[`ngSanitize`](https://docs.angularjs.org/api/ngSanitize) in your module's
|
|
106
|
+
dependencies (not in core AngularJS). To use `ngSanitize` in your module's
|
|
107
|
+
dependencies, you need to include "angular-sanitize.js" in your application. You
|
|
108
|
+
may also bypass sanitization for values you know are safe. To do so, bind to an
|
|
109
|
+
explicitly trusted value via
|
|
110
|
+
[`$sce.trustAsHtml`](https://docs.angularjs.org/api/ng/service/$sce#trustAsHtml).
|
|
111
|
+
See the example under [Strict Contextual Escaping
|
|
112
|
+
(SCE)](https://docs.angularjs.org/api/ng/service/$sce#show-me-an-example-using-sce).
|
|
113
|
+
**Note:** If a `$sanitize` service is unavailable and the bound value isn't
|
|
114
|
+
explicitly trusted, you will encounter an exception (instead of an exploit). ###
|
|
115
|
+
Element ANY ### Parameter - `ngBindHtml`:
|
|
116
|
+
[Expression](https://docs.angularjs.org/guide/expression) to evaluate. ###
|
|
117
|
+
Example ```html
|
|
118
|
+
<example
|
|
119
|
+
module="bindHtmlExample"
|
|
120
|
+
deps="angular-sanitize.js"
|
|
121
|
+
name="ng-bind-html"
|
|
122
|
+
>
|
|
123
|
+
<file name="index.html">
|
|
124
|
+
<div ng-controller="ExampleController">
|
|
125
|
+
<p ng-bind-html="myHTML"></p>
|
|
126
|
+
</div>
|
|
127
|
+
</file>
|
|
128
|
+
|
|
129
|
+
<file name="script.js">
|
|
130
|
+
angular.module('bindHtmlExample', ['ngSanitize'])
|
|
131
|
+
.controller('ExampleController', ['$scope', function($scope) { $scope.myHTML
|
|
132
|
+
= 'I am an <code>HTML</code>string with ' + '<a href="#">links!</a> and
|
|
133
|
+
other <em>stuff</em>'; }]);
|
|
134
|
+
</file>
|
|
135
|
+
|
|
136
|
+
<file name="protractor.js" type="protractor">
|
|
137
|
+
it('should check ng-bind-html', function() {
|
|
138
|
+
expect(element(by.binding('myHTML')).getText()).toBe( 'I am an HTMLstring
|
|
139
|
+
with links! and other stuff'); });
|
|
140
|
+
</file>
|
|
141
|
+
</example>
|
|
142
|
+
````
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
## ngChange Directive
|
|
2
|
+
|
|
3
|
+
### Description
|
|
4
|
+
|
|
5
|
+
Evaluate the given expression when the user changes the input. The expression is evaluated immediately, unlike the JavaScript `onchange` event which only triggers at the end of a change (usually, when the user leaves the form element or presses the return key).
|
|
6
|
+
|
|
7
|
+
The `ngChange` expression is only evaluated when a change in the input value causes a new value to be committed to the model.
|
|
8
|
+
|
|
9
|
+
### Conditions where `ngChange` is Not Evaluated
|
|
10
|
+
|
|
11
|
+
- If the value returned from the `$parsers` transformation pipeline has not changed.
|
|
12
|
+
- If the input has continued to be invalid since the model will stay `null`.
|
|
13
|
+
- If the model is changed programmatically and not by a change to the input value.
|
|
14
|
+
|
|
15
|
+
### Requirements
|
|
16
|
+
|
|
17
|
+
Note, this directive requires `ngModel` to be present.
|
|
18
|
+
|
|
19
|
+
### Element
|
|
20
|
+
|
|
21
|
+
`ANY`
|
|
22
|
+
|
|
23
|
+
### Parameters
|
|
24
|
+
|
|
25
|
+
- `ngChange` (`string`): [Expression](guide/expression) to evaluate upon change in input value.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
## `ngCloak` Directive
|
|
2
|
+
|
|
3
|
+
### Restrict
|
|
4
|
+
|
|
5
|
+
`AC`
|
|
6
|
+
|
|
7
|
+
### Description
|
|
8
|
+
|
|
9
|
+
The `ngCloak` directive is used to prevent the AngularJS HTML template from being briefly displayed by the browser in its raw (uncompiled) form while your application is loading. Use this directive to avoid the undesirable flicker effect caused by the HTML template display.
|
|
10
|
+
|
|
11
|
+
The directive can be applied to the `<body>` element, but the preferred usage is to apply multiple `ngCloak` directives to small portions of the page to permit progressive rendering of the browser view.
|
|
12
|
+
|
|
13
|
+
`ngCloak` works in cooperation with the following CSS rule embedded within `angular.js` and `angular.min.js`. For CSP mode, please add `angular-csp.css` to your HTML file (see [`ngCsp`](ng.directive:ngCsp)).
|
|
14
|
+
|
|
15
|
+
```css
|
|
16
|
+
[ng\:cloak],
|
|
17
|
+
[ng-cloak],
|
|
18
|
+
[data-ng-cloak],
|
|
19
|
+
[x-ng-cloak],
|
|
20
|
+
.ng-cloak,
|
|
21
|
+
.x-ng-cloak {
|
|
22
|
+
display: none !important;
|
|
23
|
+
}
|
|
24
|
+
```
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { directiveNormalize } from "../core/utils";
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* A collection of directives that allows creation of custom event handlers that are defined as
|
|
5
|
+
* AngularJS expressions and are compiled and executed within the current scope.
|
|
6
|
+
*/
|
|
7
|
+
export const ngEventDirectives = {};
|
|
8
|
+
|
|
9
|
+
// For events that might fire synchronously during DOM manipulation
|
|
10
|
+
// we need to execute their event handlers asynchronously using $evalAsync,
|
|
11
|
+
// so that they are not executed in an inconsistent state.
|
|
12
|
+
const forceAsyncEvents = {
|
|
13
|
+
blur: true,
|
|
14
|
+
focus: true,
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
"click dblclick submit focus blur copy cut paste"
|
|
18
|
+
.split(" ")
|
|
19
|
+
.forEach((eventName) => {
|
|
20
|
+
const directiveName = directiveNormalize(`ng-${eventName}`);
|
|
21
|
+
ngEventDirectives[directiveName] = [
|
|
22
|
+
"$parse",
|
|
23
|
+
"$rootScope",
|
|
24
|
+
"$exceptionHandler",
|
|
25
|
+
($parse, $rootScope, $exceptionHandler) => {
|
|
26
|
+
return createEventDirective(
|
|
27
|
+
$parse,
|
|
28
|
+
$rootScope,
|
|
29
|
+
$exceptionHandler,
|
|
30
|
+
directiveName,
|
|
31
|
+
eventName,
|
|
32
|
+
forceAsyncEvents[eventName],
|
|
33
|
+
);
|
|
34
|
+
},
|
|
35
|
+
];
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export function createEventDirective(
|
|
39
|
+
$parse,
|
|
40
|
+
$rootScope,
|
|
41
|
+
$exceptionHandler,
|
|
42
|
+
directiveName,
|
|
43
|
+
eventName,
|
|
44
|
+
forceAsync,
|
|
45
|
+
) {
|
|
46
|
+
return {
|
|
47
|
+
restrict: "A",
|
|
48
|
+
compile(_element, attr) {
|
|
49
|
+
// NOTE:
|
|
50
|
+
// We expose the powerful `$event` object on the scope that provides access to the Window,
|
|
51
|
+
// etc. This is OK, because expressions are not sandboxed any more (and the expression
|
|
52
|
+
// sandbox was never meant to be a security feature anyway).
|
|
53
|
+
const fn = $parse(attr[directiveName]);
|
|
54
|
+
return function ngEventHandler(scope, element) {
|
|
55
|
+
element.on(eventName, (event) => {
|
|
56
|
+
const callback = function () {
|
|
57
|
+
fn(scope, { $event: event });
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
if (!$rootScope.$$phase) {
|
|
61
|
+
scope.$apply(callback);
|
|
62
|
+
} else if (forceAsync) {
|
|
63
|
+
scope.$evalAsync(callback);
|
|
64
|
+
} else {
|
|
65
|
+
try {
|
|
66
|
+
callback();
|
|
67
|
+
} catch (error) {
|
|
68
|
+
$exceptionHandler(error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|