@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,225 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assertArgFn,
|
|
3
|
+
assertNotHasOwnProperty,
|
|
4
|
+
minErr,
|
|
5
|
+
extend,
|
|
6
|
+
isArray,
|
|
7
|
+
isObject,
|
|
8
|
+
isString,
|
|
9
|
+
getter,
|
|
10
|
+
isFunction,
|
|
11
|
+
} from "./utils";
|
|
12
|
+
|
|
13
|
+
const $controllerMinErr = minErr("$controller");
|
|
14
|
+
|
|
15
|
+
const CNTRL_REG = /^(\S+)(\s+as\s+([\w$]+))?$/;
|
|
16
|
+
export function identifierForController(controller, ident) {
|
|
17
|
+
if (ident && isString(ident)) return ident;
|
|
18
|
+
if (isString(controller)) {
|
|
19
|
+
const match = CNTRL_REG.exec(controller);
|
|
20
|
+
if (match) return match[3];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @ngdoc provider
|
|
26
|
+
* @name $controllerProvider
|
|
27
|
+
*
|
|
28
|
+
*
|
|
29
|
+
* @description
|
|
30
|
+
* The {@link ng.$controller $controller service} is used by AngularJS to create new
|
|
31
|
+
* controllers.
|
|
32
|
+
*
|
|
33
|
+
* This provider allows controller registration via the
|
|
34
|
+
* {@link ng.$controllerProvider#register register} method.
|
|
35
|
+
*/
|
|
36
|
+
export function $ControllerProvider() {
|
|
37
|
+
const controllers = {};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @ngdoc method
|
|
41
|
+
* @name $controllerProvider#has
|
|
42
|
+
* @param {string} name Controller name to check.
|
|
43
|
+
*/
|
|
44
|
+
this.has = function (name) {
|
|
45
|
+
return Object.prototype.hasOwnProperty.call(controllers, name);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @ngdoc method
|
|
50
|
+
* @name $controllerProvider#register
|
|
51
|
+
* @param {string|Object} name Controller name, or an object map of controllers where the keys are
|
|
52
|
+
* the names and the values are the constructors.
|
|
53
|
+
* @param {Function|Array} constructor Controller constructor fn (optionally decorated with DI
|
|
54
|
+
* annotations in the array notation).
|
|
55
|
+
*/
|
|
56
|
+
this.register = function (name, constructor) {
|
|
57
|
+
assertNotHasOwnProperty(name, "controller");
|
|
58
|
+
if (isObject(name)) {
|
|
59
|
+
extend(controllers, name);
|
|
60
|
+
} else {
|
|
61
|
+
controllers[name] = constructor;
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
this.$get = [
|
|
66
|
+
"$injector",
|
|
67
|
+
function ($injector) {
|
|
68
|
+
/**
|
|
69
|
+
* @ngdoc service
|
|
70
|
+
* @name $controller
|
|
71
|
+
* @requires $injector
|
|
72
|
+
*
|
|
73
|
+
* @param {Function|string} expression If called with a function then it's considered to be the
|
|
74
|
+
* controller constructor function. Otherwise it's considered to be a string which is used
|
|
75
|
+
* to retrieve the controller constructor using the following steps:
|
|
76
|
+
*
|
|
77
|
+
* * check if a controller with given name is registered via `$controllerProvider`
|
|
78
|
+
* * check if evaluating the string on the current scope returns a constructor
|
|
79
|
+
*
|
|
80
|
+
* The string can use the `controller as property` syntax, where the controller instance is published
|
|
81
|
+
* as the specified property on the `scope`; the `scope` must be injected into `locals` param for this
|
|
82
|
+
* to work correctly.
|
|
83
|
+
*
|
|
84
|
+
* @param {Object} locals Injection locals for Controller.
|
|
85
|
+
* @return {Object} Instance of given controller.
|
|
86
|
+
*
|
|
87
|
+
* @description
|
|
88
|
+
* `$controller` service is responsible for instantiating controllers.
|
|
89
|
+
*
|
|
90
|
+
* It's just a simple call to {@link auto.$injector $injector}, but extracted into
|
|
91
|
+
* a service, so that one can override this service with [BC version](https://gist.github.com/1649788).
|
|
92
|
+
*/
|
|
93
|
+
return function $controller(expression, locals, later, ident) {
|
|
94
|
+
// PRIVATE API:
|
|
95
|
+
// param `later` --- indicates that the controller's constructor is invoked at a later time.
|
|
96
|
+
// If true, $controller will allocate the object with the correct
|
|
97
|
+
// prototype chain, but will not invoke the controller until a returned
|
|
98
|
+
// callback is invoked.
|
|
99
|
+
// param `ident` --- An optional label which overrides the label parsed from the controller
|
|
100
|
+
// expression, if any.
|
|
101
|
+
let instance;
|
|
102
|
+
let match;
|
|
103
|
+
let constructor;
|
|
104
|
+
let identifier;
|
|
105
|
+
later = later === true;
|
|
106
|
+
if (ident && isString(ident)) {
|
|
107
|
+
identifier = ident;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (isString(expression)) {
|
|
111
|
+
match = /** @type {string} */ (expression).match(CNTRL_REG);
|
|
112
|
+
if (!match) {
|
|
113
|
+
throw $controllerMinErr(
|
|
114
|
+
"ctrlfmt",
|
|
115
|
+
"Badly formed controller string '{0}'. " +
|
|
116
|
+
"Must match `__name__ as __id__` or `__name__`.",
|
|
117
|
+
expression,
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
constructor = match[1];
|
|
121
|
+
identifier = identifier || match[3];
|
|
122
|
+
expression = Object.prototype.hasOwnProperty.call(
|
|
123
|
+
controllers,
|
|
124
|
+
constructor,
|
|
125
|
+
)
|
|
126
|
+
? controllers[constructor]
|
|
127
|
+
: getter(locals.$scope, constructor, true);
|
|
128
|
+
|
|
129
|
+
if (!expression) {
|
|
130
|
+
throw $controllerMinErr(
|
|
131
|
+
"ctrlreg",
|
|
132
|
+
"The controller with the name '{0}' is not registered.",
|
|
133
|
+
constructor,
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
assertArgFn(expression, constructor, true);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (later) {
|
|
141
|
+
// Instantiate controller later:
|
|
142
|
+
// This machinery is used to create an instance of the object before calling the
|
|
143
|
+
// controller's constructor itself.
|
|
144
|
+
//
|
|
145
|
+
// This allows properties to be added to the controller before the constructor is
|
|
146
|
+
// invoked. Primarily, this is used for isolate scope bindings in $compile.
|
|
147
|
+
//
|
|
148
|
+
// This feature is not intended for use by applications, and is thus not documented
|
|
149
|
+
// publicly.
|
|
150
|
+
// Object creation: http://jsperf.com/create-constructor/2
|
|
151
|
+
const controllerPrototype = (
|
|
152
|
+
isArray(expression) ? expression[expression.length - 1] : expression
|
|
153
|
+
).prototype;
|
|
154
|
+
instance = Object.create(controllerPrototype || null);
|
|
155
|
+
|
|
156
|
+
if (identifier) {
|
|
157
|
+
addIdentifier(
|
|
158
|
+
locals,
|
|
159
|
+
identifier,
|
|
160
|
+
instance,
|
|
161
|
+
constructor || expression.name,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return extend(
|
|
166
|
+
() => {
|
|
167
|
+
const result = $injector.invoke(
|
|
168
|
+
expression,
|
|
169
|
+
instance,
|
|
170
|
+
locals,
|
|
171
|
+
constructor,
|
|
172
|
+
);
|
|
173
|
+
if (
|
|
174
|
+
result !== instance &&
|
|
175
|
+
(isObject(result) || isFunction(result))
|
|
176
|
+
) {
|
|
177
|
+
instance = result;
|
|
178
|
+
if (identifier) {
|
|
179
|
+
// If result changed, re-assign controllerAs value to scope.
|
|
180
|
+
addIdentifier(
|
|
181
|
+
locals,
|
|
182
|
+
identifier,
|
|
183
|
+
instance,
|
|
184
|
+
constructor || expression.name,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return instance;
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
instance,
|
|
192
|
+
identifier,
|
|
193
|
+
},
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
instance = $injector.instantiate(expression, locals, constructor);
|
|
198
|
+
|
|
199
|
+
if (identifier) {
|
|
200
|
+
addIdentifier(
|
|
201
|
+
locals,
|
|
202
|
+
identifier,
|
|
203
|
+
instance,
|
|
204
|
+
constructor || expression.name,
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return instance;
|
|
209
|
+
};
|
|
210
|
+
|
|
211
|
+
function addIdentifier(locals, identifier, instance, name) {
|
|
212
|
+
if (!(locals && isObject(locals.$scope))) {
|
|
213
|
+
throw minErr("$controller")(
|
|
214
|
+
"noscp",
|
|
215
|
+
"Cannot export controller '{0}' as '{1}'! No $scope object provided via `locals`.",
|
|
216
|
+
name,
|
|
217
|
+
identifier,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
locals.$scope[identifier] = instance;
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
];
|
|
225
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
/**
|
|
3
|
+
* @ngdoc service
|
|
4
|
+
* @name $exceptionHandler
|
|
5
|
+
* @requires ng.$log
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @description
|
|
9
|
+
* Any uncaught exception in AngularJS expressions is delegated to this service.
|
|
10
|
+
* The default implementation simply delegates to `$log.error` which logs it into
|
|
11
|
+
* the browser console.
|
|
12
|
+
*
|
|
13
|
+
*
|
|
14
|
+
* ## Example:
|
|
15
|
+
*
|
|
16
|
+
* The example below will overwrite the default `$exceptionHandler` in order to (a) log uncaught
|
|
17
|
+
* errors to the backend for later inspection by the developers and (b) to use `$log.warn()` instead
|
|
18
|
+
* of `$log.error()`.
|
|
19
|
+
*
|
|
20
|
+
* ```js
|
|
21
|
+
* angular.
|
|
22
|
+
* module('exceptionOverwrite', []).
|
|
23
|
+
* factory('$exceptionHandler', ['$log', 'logErrorsToBackend', function($log, logErrorsToBackend) {
|
|
24
|
+
* return function myExceptionHandler(exception, cause) {
|
|
25
|
+
* logErrorsToBackend(exception, cause);
|
|
26
|
+
* $log.warn(exception, cause);
|
|
27
|
+
* };
|
|
28
|
+
* }]);
|
|
29
|
+
* ```
|
|
30
|
+
*
|
|
31
|
+
* <hr />
|
|
32
|
+
* Note, that code executed in event-listeners (even those registered using jqLite's `on`/`bind`
|
|
33
|
+
* methods) does not delegate exceptions to the {@link ng.$exceptionHandler $exceptionHandler}
|
|
34
|
+
* (unless executed during a digest).
|
|
35
|
+
*
|
|
36
|
+
* If you wish, you can manually delegate exceptions, e.g.
|
|
37
|
+
* `try { ... } catch(e) { $exceptionHandler(e); }`
|
|
38
|
+
*
|
|
39
|
+
* @param {Error} exception Exception associated with the error.
|
|
40
|
+
* @param {string=} cause Optional information about the context in which
|
|
41
|
+
* the error was thrown.
|
|
42
|
+
*
|
|
43
|
+
*/
|
|
44
|
+
export function $ExceptionHandlerProvider() {
|
|
45
|
+
this.$get = [
|
|
46
|
+
"$log",
|
|
47
|
+
function ($log) {
|
|
48
|
+
return function () {
|
|
49
|
+
$log.error.apply($log, arguments);
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// let $log;
|
|
56
|
+
|
|
57
|
+
// export function ExceptionHandler(log) {
|
|
58
|
+
// $log = log || window.console;
|
|
59
|
+
|
|
60
|
+
// return function(exception, cause) {
|
|
61
|
+
// $log.error.apply($log, arguments);
|
|
62
|
+
// };
|
|
63
|
+
// }
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { forEach, isObject } from "./utils";
|
|
2
|
+
import { filterFilter } from "../filters/filter";
|
|
3
|
+
import { jsonFilter } from "../filters/filters";
|
|
4
|
+
import { limitToFilter } from "../filters/limit-to";
|
|
5
|
+
import { orderByFilter } from "../filters/order-by";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @ngdoc provider
|
|
9
|
+
* @name $filterProvider
|
|
10
|
+
* @description
|
|
11
|
+
*
|
|
12
|
+
* Filters are just functions which transform input to an output. However filters need to be
|
|
13
|
+
* Dependency Injected. To achieve this a filter definition consists of a factory function which is
|
|
14
|
+
* annotated with dependencies and is responsible for creating a filter function.
|
|
15
|
+
*
|
|
16
|
+
* <div class="alert alert-warning">
|
|
17
|
+
* **Note:** Filter names must be valid AngularJS {@link expression} identifiers, such as `uppercase` or `orderBy`.
|
|
18
|
+
* Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace
|
|
19
|
+
* your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores
|
|
20
|
+
* (`myapp_subsection_filterx`).
|
|
21
|
+
* </div>
|
|
22
|
+
*
|
|
23
|
+
* ```js
|
|
24
|
+
* // Filter registration
|
|
25
|
+
* function MyModule($provide, $filterProvider) {
|
|
26
|
+
* // create a service to demonstrate injection (not always needed)
|
|
27
|
+
* $provide.value('greet', function(name){
|
|
28
|
+
* return 'Hello ' + name + '!';
|
|
29
|
+
* });
|
|
30
|
+
*
|
|
31
|
+
* // register a filter factory which uses the
|
|
32
|
+
* // greet service to demonstrate DI.
|
|
33
|
+
* $filterProvider.register('greet', function(greet){
|
|
34
|
+
* // return the filter function which uses the greet service
|
|
35
|
+
* // to generate salutation
|
|
36
|
+
* return function(text) {
|
|
37
|
+
* // filters need to be forgiving so check input validity
|
|
38
|
+
* return text && greet(text) || text;
|
|
39
|
+
* };
|
|
40
|
+
* });
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* The filter function is registered with the `$injector` under the filter name suffix with
|
|
45
|
+
* `Filter`.
|
|
46
|
+
*
|
|
47
|
+
* ```js
|
|
48
|
+
* it('should be the same instance', inject(
|
|
49
|
+
* function($filterProvider) {
|
|
50
|
+
* $filterProvider.register('reverse', function(){
|
|
51
|
+
* return ...;
|
|
52
|
+
* });
|
|
53
|
+
* },
|
|
54
|
+
* function($filter, reverseFilter) {
|
|
55
|
+
* expect($filter('reverse')).toBe(reverseFilter);
|
|
56
|
+
* });
|
|
57
|
+
* ```
|
|
58
|
+
*
|
|
59
|
+
*
|
|
60
|
+
* For more information about how AngularJS filters work, and how to create your own filters, see
|
|
61
|
+
* {@link guide/filter Filters} in the AngularJS Developer Guide.
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* @ngdoc service
|
|
66
|
+
* @name $filter
|
|
67
|
+
* @kind function
|
|
68
|
+
* @description
|
|
69
|
+
* Filters are used for formatting data displayed to the user.
|
|
70
|
+
*
|
|
71
|
+
* They can be used in view templates, controllers or services. AngularJS comes
|
|
72
|
+
* with a collection of [built-in filters](api/ng/filter), but it is easy to
|
|
73
|
+
* define your own as well.
|
|
74
|
+
*
|
|
75
|
+
* The general syntax in templates is as follows:
|
|
76
|
+
*
|
|
77
|
+
* ```html
|
|
78
|
+
* {{ expression [| filter_name[:parameter_value] ... ] }}
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @param {String} name Name of the filter function to retrieve
|
|
82
|
+
* @return {Function} the filter function
|
|
83
|
+
* @example
|
|
84
|
+
<example name="$filter" module="filterExample">
|
|
85
|
+
<file name="index.html">
|
|
86
|
+
<div ng-controller="MainCtrl">
|
|
87
|
+
<h3>{{ originalText }}</h3>
|
|
88
|
+
<h3>{{ filteredText }}</h3>
|
|
89
|
+
</div>
|
|
90
|
+
</file>
|
|
91
|
+
|
|
92
|
+
<file name="script.js">
|
|
93
|
+
angular.module('filterExample', [])
|
|
94
|
+
.controller('MainCtrl', function($scope, $filter) {
|
|
95
|
+
$scope.originalText = 'hello';
|
|
96
|
+
$scope.filteredText = $filter('uppercase')($scope.originalText);
|
|
97
|
+
});
|
|
98
|
+
</file>
|
|
99
|
+
</example>
|
|
100
|
+
*/
|
|
101
|
+
$FilterProvider.$inject = ["$provide"];
|
|
102
|
+
export function $FilterProvider($provide) {
|
|
103
|
+
const suffix = "Filter";
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* @ngdoc method
|
|
107
|
+
* @name $filterProvider#register
|
|
108
|
+
* @param {string|Object} name Name of the filter function, or an object map of filters where
|
|
109
|
+
* the keys are the filter names and the values are the filter factories.
|
|
110
|
+
*
|
|
111
|
+
* <div class="alert alert-warning">
|
|
112
|
+
* **Note:** Filter names must be valid AngularJS {@link expression} identifiers, such as `uppercase` or `orderBy`.
|
|
113
|
+
* Names with special characters, such as hyphens and dots, are not allowed. If you wish to namespace
|
|
114
|
+
* your filters, then you can use capitalization (`myappSubsectionFilterx`) or underscores
|
|
115
|
+
* (`myapp_subsection_filterx`).
|
|
116
|
+
* </div>
|
|
117
|
+
* @param {Function} factory If the first argument was a string, a factory function for the filter to be registered.
|
|
118
|
+
* @returns {Object} Registered filter instance, or if a map of filters was provided then a map
|
|
119
|
+
* of the registered filter instances.
|
|
120
|
+
*/
|
|
121
|
+
function register(name, factory) {
|
|
122
|
+
if (isObject(name)) {
|
|
123
|
+
const filters = {};
|
|
124
|
+
forEach(name, (filter, key) => {
|
|
125
|
+
filters[key] = register(key, filter);
|
|
126
|
+
});
|
|
127
|
+
return filters;
|
|
128
|
+
}
|
|
129
|
+
return $provide.factory(name + suffix, factory);
|
|
130
|
+
}
|
|
131
|
+
this.register = register;
|
|
132
|
+
|
|
133
|
+
this.$get = [
|
|
134
|
+
"$injector",
|
|
135
|
+
function ($injector) {
|
|
136
|
+
return function (name) {
|
|
137
|
+
return $injector.get(name + suffix);
|
|
138
|
+
};
|
|
139
|
+
},
|
|
140
|
+
];
|
|
141
|
+
|
|
142
|
+
register("filter", filterFilter);
|
|
143
|
+
register("json", jsonFilter);
|
|
144
|
+
register("limitTo", limitToFilter);
|
|
145
|
+
register("orderBy", orderByFilter);
|
|
146
|
+
}
|