@angular-wave/angular.ts 0.0.65 → 0.0.67
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/dist/angular-ts.esm.js +2 -2
- package/dist/angular-ts.umd.js +2 -2
- package/package.json +1 -1
- package/src/animations/animate-js.js +6 -0
- package/src/animations/animate-swap.js +3 -0
- package/src/animations/animation.js +1 -1
- package/src/core/compile/compile.js +16 -4
- package/src/core/controller/controller.js +5 -5
- package/src/core/di/injector.js +133 -259
- package/src/core/di/injector.md +3 -3
- package/src/core/di/injector.spec.js +30 -24
- package/src/core/di/internal-injector.js +286 -0
- package/src/core/filter/filter.js +5 -0
- package/src/core/parser/parse.js +1 -12
- package/src/core/parser/parse.spec.js +96 -110
- package/src/core/sce/sce.js +6 -1
- package/src/core/timeout/timeout.js +110 -111
- package/src/directive/input/input.js +32 -726
- package/src/directive/input/input.md +706 -0
- package/src/directive/select/select.js +48 -122
- package/src/directive/select/select.md +74 -0
- package/src/directive/show-hide/show-hide.js +13 -224
- package/src/directive/show-hide/show-hide.md +257 -0
- package/src/filters/limit-to.spec.js +1 -1
- package/src/filters/order-by.spec.js +1 -1
- package/src/index.js +6 -2
- package/src/loader.js +8 -4
- package/src/public.js +1 -7
- package/src/router/services.js +9 -4
- package/src/router/state/state-builder.js +6 -7
- package/src/router/state/state-registry.js +5 -0
- package/src/router/state/state-service.js +1 -1
- package/src/router/state/views.js +2 -1
- package/src/router/state-provider.js +1 -1
- package/src/router/template-factory.js +15 -14
- package/src/router/url/url-service.js +4 -4
- package/src/services/anchor-scroll.js +2 -2
- package/src/services/browser.js +2 -9
- package/src/services/cache-factory.js +0 -67
- package/src/services/cache-factory.md +75 -0
- package/src/services/cookie-reader.js +36 -55
- package/src/services/http/http.js +73 -586
- package/src/services/http/http.md +413 -0
- package/src/services/http-backend/http-backend.js +19 -44
- package/src/services/template-request.js +1 -9
- package/src/shared/jqlite/jqlite.js +4 -69
- package/src/types.js +8 -12
- package/types/animations/animate-js.d.ts +1 -1
- package/types/animations/animate-swap.d.ts +4 -7
- package/types/animations/animation.d.ts +1 -1
- package/types/core/compile/compile.d.ts +7 -7
- package/types/core/controller/controller.d.ts +1 -6
- package/types/core/di/injector.d.ts +13 -7
- package/types/core/di/internal-injector.d.ts +91 -0
- package/types/core/exception-handler.d.ts +1 -1
- package/types/core/filter/filter.d.ts +1 -1
- package/types/core/parser/parse.d.ts +1 -1
- package/types/core/sce/sce.d.ts +1 -1
- package/types/core/timeout/timeout.d.ts +16 -26
- package/types/directive/input/input.d.ts +19 -124
- package/types/directive/select/select.d.ts +7 -74
- package/types/directive/show-hide/show-hide.d.ts +11 -224
- package/types/loader.d.ts +4 -4
- package/types/router/services.d.ts +8 -1
- package/types/router/state/state-builder.d.ts +1 -2
- package/types/router/state/state-registry.d.ts +2 -2
- package/types/router/state/state-service.d.ts +2 -2
- package/types/router/state-provider.d.ts +2 -2
- package/types/router/template-factory.d.ts +16 -16
- package/types/router/url/url-service.d.ts +4 -4
- package/types/services/anchor-scroll.d.ts +1 -1
- package/types/services/browser.d.ts +0 -10
- package/types/services/cache-factory.d.ts +0 -67
- package/types/services/cookie-reader.d.ts +2 -10
- package/types/services/http/http.d.ts +53 -61
- package/types/services/http-backend/http-backend.d.ts +8 -31
- package/types/services/template-request.d.ts +1 -9
- package/types/shared/jqlite/jqlite.d.ts +9 -9
- package/types/types.d.ts +5 -38
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
_ The `$http` service is a core AngularJS service that facilitates communication with the remote
|
|
3
|
+
_ HTTP servers via the browser's [XMLHttpRequest](https://developer.mozilla.org/en/xmlhttprequest)
|
|
4
|
+
_ object or via [JSONP](http://en.wikipedia.org/wiki/JSONP).
|
|
5
|
+
_
|
|
6
|
+
_ For unit testing applications that use `$http` service, see
|
|
7
|
+
_ {@link ngMock.$httpBackend $httpBackend mock}.
|
|
8
|
+
*
|
|
9
|
+
* For a higher level of abstraction, please check out the {@link ngResource.$resource
|
|
10
|
+
_ $resource} service.
|
|
11
|
+
_
|
|
12
|
+
_ The $http API is based on the {@link ng.$q deferred/promise APIs} exposed by
|
|
13
|
+
_ the $q service. While for simple usage patterns this doesn't matter much, for advanced usage
|
|
14
|
+
* it is important to familiarize yourself with these APIs and the guarantees they provide.
|
|
15
|
+
*
|
|
16
|
+
*
|
|
17
|
+
* ## General usage
|
|
18
|
+
* The `$http`service is a function which takes a single argument — a {@link $http#usage configuration object} —
|
|
19
|
+
* that is used to generate an HTTP request and returns a {@link ng.$q promise} that is
|
|
20
|
+
* resolved (request success) or rejected (request failure) with a
|
|
21
|
+
* {@link ng.$http#$http-returns response} object.
|
|
22
|
+
*
|
|
23
|
+
* ```js
|
|
24
|
+
* // Simple GET request example:
|
|
25
|
+
* $http({
|
|
26
|
+
* method: 'GET',
|
|
27
|
+
* url: '/someUrl'
|
|
28
|
+
* }).then(function successCallback(response) {
|
|
29
|
+
* // this callback will be called asynchronously
|
|
30
|
+
* // when the response is available
|
|
31
|
+
* }, function errorCallback(response) {
|
|
32
|
+
* // called asynchronously if an error occurs
|
|
33
|
+
* // or server returns response with an error status.
|
|
34
|
+
* });
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
*
|
|
38
|
+
* ## Shortcut methods
|
|
39
|
+
*
|
|
40
|
+
* Shortcut methods are also available. All shortcut methods require passing in the URL, and
|
|
41
|
+
* request data must be passed in for POST/PUT requests. An optional config can be passed as the
|
|
42
|
+
* last argument.
|
|
43
|
+
*
|
|
44
|
+
* ```js
|
|
45
|
+
* $http.get('/someUrl', config).then(successCallback, errorCallback);
|
|
46
|
+
* $http.post('/someUrl', data, config).then(successCallback, errorCallback);
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* Complete list of shortcut methods:
|
|
50
|
+
*
|
|
51
|
+
* - {@link ng.$http#get $http.get}
|
|
52
|
+
* - {@link ng.$http#head $http.head}
|
|
53
|
+
* - {@link ng.$http#post $http.post}
|
|
54
|
+
* - {@link ng.$http#put $http.put}
|
|
55
|
+
* - {@link ng.$http#delete $http.delete}
|
|
56
|
+
* - {@link ng.$http#patch $http.patch}
|
|
57
|
+
*
|
|
58
|
+
*
|
|
59
|
+
* ```
|
|
60
|
+
* $http.get(...);
|
|
61
|
+
* $httpBackend.flush();
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* ## Setting HTTP Headers
|
|
65
|
+
*
|
|
66
|
+
* The $http service will automatically add certain HTTP headers to all requests. These defaults
|
|
67
|
+
* can be fully configured by accessing the`$httpProvider.defaults.headers` configuration
|
|
68
|
+
* object, which currently contains this default configuration:
|
|
69
|
+
*
|
|
70
|
+
* - `$httpProvider.defaults.headers.common`(headers that are common for all requests):
|
|
71
|
+
* - <code>Accept: application/json, text/plain, \*/\*</code>
|
|
72
|
+
* -`$httpProvider.defaults.headers.post`: (header defaults for POST requests)
|
|
73
|
+
* - `Content-Type: application/json`
|
|
74
|
+
* - `$httpProvider.defaults.headers.put`(header defaults for PUT requests)
|
|
75
|
+
* -`Content-Type: application/json` *
|
|
76
|
+
* To add or overwrite these defaults, simply add or remove a property from these configuration
|
|
77
|
+
* objects. To add headers for an HTTP method other than POST or PUT, simply add a new object
|
|
78
|
+
* with the lowercased HTTP method name as the key, e.g.
|
|
79
|
+
*`$httpProvider.defaults.headers.get = { 'My-Header' : 'value' }`.
|
|
80
|
+
*
|
|
81
|
+
* The defaults can also be set at runtime via the `$http.defaults`object in the same
|
|
82
|
+
* fashion. For example:
|
|
83
|
+
*
|
|
84
|
+
* ```
|
|
85
|
+
* module.run(function($http) {
|
|
86
|
+
* $http.defaults.headers.common.Authorization = 'Basic YmVlcDpib29w';
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* In addition, you can supply a`headers`property in the config object passed when
|
|
91
|
+
* calling`$http(config)`, which overrides the defaults without changing them globally.
|
|
92
|
+
*
|
|
93
|
+
* To explicitly remove a header automatically added via $httpProvider.defaults.headers on a per request basis,
|
|
94
|
+
* Use the `headers`property, setting the desired header to`undefined`. For example:
|
|
95
|
+
*
|
|
96
|
+
* ```js
|
|
97
|
+
* let req = {
|
|
98
|
+
* method: 'POST',
|
|
99
|
+
* url: 'http://example.com',
|
|
100
|
+
* headers: {
|
|
101
|
+
* 'Content-Type': undefined
|
|
102
|
+
* },
|
|
103
|
+
* data: { test: 'test' }
|
|
104
|
+
* }
|
|
105
|
+
*
|
|
106
|
+
* $http(req).then(function(){...}, function(){...});
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* ## Transforming Requests and Responses
|
|
110
|
+
*
|
|
111
|
+
* Both requests and responses can be transformed using transformation functions: `transformRequest` * and`transformResponse`. These properties can be a single function that returns
|
|
112
|
+
* the transformed value (`function(data, headersGetter, status)`) or an array of such transformation functions,
|
|
113
|
+
* which allows you to `push`or`unshift` a new transformation function into the transformation chain. \*
|
|
114
|
+
_ <div class="alert alert-warning">
|
|
115
|
+
_ **Note:** AngularJS does not make a copy of the `data` parameter before it is passed into the `transformRequest` pipeline.
|
|
116
|
+
_ That means changes to the properties of `data` are not local to the transform function (since Javascript passes objects by reference).
|
|
117
|
+
_ For example, when calling `$http.get(url, $scope.myObject)`, modifications to the object's properties in a transformRequest
|
|
118
|
+
_ function will be reflected on the scope and in any templates where the object is data-bound.
|
|
119
|
+
_ To prevent this, transform functions should have no side-effects.
|
|
120
|
+
_ If you need to modify properties, it is recommended to make a copy of the data, or create new object to return.
|
|
121
|
+
_ </div> \*
|
|
122
|
+
_ ### Default Transformations
|
|
123
|
+
_
|
|
124
|
+
_ The `$httpProvider` provider and `$http` service expose `defaults.transformRequest` and
|
|
125
|
+
_ `defaults.transformResponse` properties. If a request does not provide its own transformations
|
|
126
|
+
_ then these will be applied.
|
|
127
|
+
_
|
|
128
|
+
_ You can augment or replace the default transformations by modifying these properties by adding to or
|
|
129
|
+
_ replacing the array. \*
|
|
130
|
+
_ AngularJS provides the following default transformations:
|
|
131
|
+
_
|
|
132
|
+
_ Request transformations (`$httpProvider.defaults.transformRequest` and `$http.defaults.transformRequest`) is
|
|
133
|
+
_ an array with one function that does the following: \*
|
|
134
|
+
_ - If the `data` property of the request configuration object contains an object, serialize it
|
|
135
|
+
_ into JSON format. \*
|
|
136
|
+
_ Response transformations (`$httpProvider.defaults.transformResponse` and `$http.defaults.transformResponse`) is
|
|
137
|
+
_ an array with one function that does the following: \*
|
|
138
|
+
_ - If XSRF prefix is detected, strip it (see Security Considerations section below).
|
|
139
|
+
_ - If the `Content-Type` is `application/json` or the response looks like JSON,
|
|
140
|
+
_ deserialize it using a JSON parser.
|
|
141
|
+
_ \*
|
|
142
|
+
_ ### Overriding the Default Transformations Per Request
|
|
143
|
+
_
|
|
144
|
+
_ If you wish to override the request/response transformations only for a single request then provide
|
|
145
|
+
_ `transformRequest` and/or `transformResponse` properties on the configuration object passed
|
|
146
|
+
_ into `$http`.
|
|
147
|
+
_
|
|
148
|
+
_ Note that if you provide these properties on the config object the default transformations will be
|
|
149
|
+
_ overwritten. If you wish to augment the default transformations then you must include them in your
|
|
150
|
+
_ local transformation array.
|
|
151
|
+
_
|
|
152
|
+
_ The following code demonstrates adding a new response transformation to be run after the default response
|
|
153
|
+
_ transformations have been run. \*
|
|
154
|
+
_ ```js
|
|
155
|
+
_ function appendTransform(defaults, transform) { \*
|
|
156
|
+
_ // We can't guarantee that the default transformation is an array
|
|
157
|
+
_ defaults = angular.isArray(defaults) ? defaults : [defaults]; \*
|
|
158
|
+
_ // Append the new transformation to the defaults
|
|
159
|
+
_ return defaults.concat(transform);
|
|
160
|
+
_ }
|
|
161
|
+
_
|
|
162
|
+
_ $http({
|
|
163
|
+
_ url: '...',
|
|
164
|
+
_ method: 'GET',
|
|
165
|
+
_ transformResponse: appendTransform($http.defaults.transformResponse, function(value) {
|
|
166
|
+
* return doTransform(value);
|
|
167
|
+
* })
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
*
|
|
172
|
+
* ## Caching
|
|
173
|
+
*
|
|
174
|
+
* {@link ng.$http `$http`} responses are not cached by default. To enable caching, you must
|
|
175
|
+
_ set the config.cache value or the default cache value to TRUE or to a cache object (created
|
|
176
|
+
_ with {@link ng.$cacheFactory `$cacheFactory`}). If defined, the value of config.cache takes
|
|
177
|
+
* precedence over the default cache value.
|
|
178
|
+
*
|
|
179
|
+
* In order to:
|
|
180
|
+
* * cache all responses - set the default cache value to TRUE or to a cache object
|
|
181
|
+
* * cache a specific response - set config.cache value to TRUE or to a cache object
|
|
182
|
+
*
|
|
183
|
+
* If caching is enabled, but neither the default cache nor config.cache are set to a cache object,
|
|
184
|
+
* then the default `$cacheFactory("$http")`object is used.
|
|
185
|
+
*
|
|
186
|
+
* The default cache value can be set by updating the
|
|
187
|
+
* {@link ng.$http#defaults`$http.defaults.cache`} property or the
|
|
188
|
+
* {@link $httpProvider#defaults `$httpProvider.defaults.cache`} property.
|
|
189
|
+
*
|
|
190
|
+
* When caching is enabled, {@link ng.$http `$http`} stores the response from the server using
|
|
191
|
+
* the relevant cache object. The next time the same request is made, the response is returned
|
|
192
|
+
* from the cache without sending a request to the server.
|
|
193
|
+
*
|
|
194
|
+
* Take note that:
|
|
195
|
+
*
|
|
196
|
+
* * Only GET and JSONP requests are cached.
|
|
197
|
+
* * The cache key is the request URL including search parameters; headers are not considered.
|
|
198
|
+
* * Cached responses are returned asynchronously, in the same way as responses from the server.
|
|
199
|
+
* * If multiple identical requests are made using the same cache, which is not yet populated,
|
|
200
|
+
* one request will be made to the server and remaining requests will return the same response.
|
|
201
|
+
* * A cache-control header on the response does not affect if or how responses are cached.
|
|
202
|
+
*
|
|
203
|
+
*
|
|
204
|
+
* ## Interceptors
|
|
205
|
+
*
|
|
206
|
+
* Before you start creating interceptors, be sure to understand the
|
|
207
|
+
* {@link ng.$q $q and deferred/promise APIs}.
|
|
208
|
+
*
|
|
209
|
+
* For purposes of global error handling, authentication, or any kind of synchronous or
|
|
210
|
+
* asynchronous pre-processing of request or postprocessing of responses, it is desirable to be
|
|
211
|
+
* able to intercept requests before they are handed to the server and
|
|
212
|
+
* responses before they are handed over to the application code that
|
|
213
|
+
* initiated these requests. The interceptors leverage the {@link ng.$q
|
|
214
|
+
_ promise APIs} to fulfill this need for both synchronous and asynchronous pre-processing.
|
|
215
|
+
_
|
|
216
|
+
_ The interceptors are service factories that are registered with the `$httpProvider` by
|
|
217
|
+
_ adding them to the `$httpProvider.interceptors` array. The factory is called and
|
|
218
|
+
_ injected with dependencies (if specified) and returns the interceptor.
|
|
219
|
+
_
|
|
220
|
+
_ There are two kinds of interceptors (and two kinds of rejection interceptors):
|
|
221
|
+
_ \* _ `request`: interceptors get called with a http {@link $http#usage config} object. The function is free to
|
|
222
|
+
_ modify the `config` object or create a new one. The function needs to return the `config`
|
|
223
|
+
_ object directly, or a promise containing the `config` or a new `config` object.
|
|
224
|
+
_ _ `requestError`: interceptor gets called when a previous interceptor threw an error or
|
|
225
|
+
_ resolved with a rejection. \* _ `response`: interceptors get called with http `response` object. The function is free to
|
|
226
|
+
_ modify the `response` object or create a new one. The function needs to return the `response`
|
|
227
|
+
_ object directly, or as a promise containing the `response` or a new `response` object.
|
|
228
|
+
_ _ `responseError`: interceptor gets called when a previous interceptor threw an error or
|
|
229
|
+
_ resolved with a rejection. \* \*
|
|
230
|
+
_ ```js
|
|
231
|
+
_ // register the interceptor as a service
|
|
232
|
+
_ $provide.factory('myHttpInterceptor', function($q, dependency1, dependency2) {
|
|
233
|
+
_ return {
|
|
234
|
+
_ // optional method
|
|
235
|
+
_ 'request': function(config) {
|
|
236
|
+
_ // do something on success
|
|
237
|
+
_ return config;
|
|
238
|
+
_ },
|
|
239
|
+
_
|
|
240
|
+
_ // optional method
|
|
241
|
+
_ 'requestError': function(rejection) {
|
|
242
|
+
_ // do something on error
|
|
243
|
+
_ if (canRecover(rejection)) {
|
|
244
|
+
_ return responseOrNewPromise
|
|
245
|
+
_ }
|
|
246
|
+
_ return $q.reject(rejection);
|
|
247
|
+
_ }, \* \* \*
|
|
248
|
+
_ // optional method
|
|
249
|
+
_ 'response': function(response) {
|
|
250
|
+
_ // do something on success
|
|
251
|
+
_ return response;
|
|
252
|
+
_ },
|
|
253
|
+
_
|
|
254
|
+
_ // optional method
|
|
255
|
+
_ 'responseError': function(rejection) {
|
|
256
|
+
_ // do something on error
|
|
257
|
+
_ if (canRecover(rejection)) {
|
|
258
|
+
_ return responseOrNewPromise
|
|
259
|
+
_ }
|
|
260
|
+
_ return $q.reject(rejection);
|
|
261
|
+
_ }
|
|
262
|
+
_ };
|
|
263
|
+
_ }); \*
|
|
264
|
+
_ $httpProvider.interceptors.push('myHttpInterceptor');
|
|
265
|
+
_ \*
|
|
266
|
+
_ // alternatively, register the interceptor via an anonymous factory
|
|
267
|
+
_ $httpProvider.interceptors.push(function($q, dependency1, dependency2) {
|
|
268
|
+
_ return {
|
|
269
|
+
_ 'request': function(config) {
|
|
270
|
+
_ // same as above
|
|
271
|
+
_ }, \*
|
|
272
|
+
_ 'response': function(response) {
|
|
273
|
+
_ // same as above
|
|
274
|
+
_ }
|
|
275
|
+
_ };
|
|
276
|
+
_ });
|
|
277
|
+
_ `` *
|
|
278
|
+
* ## Security Considerations
|
|
279
|
+
*
|
|
280
|
+
* When designing web applications, consider security threats from:
|
|
281
|
+
*
|
|
282
|
+
* - [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
|
|
283
|
+
* - [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery)
|
|
284
|
+
*
|
|
285
|
+
* Both server and the client must cooperate in order to eliminate these threats. AngularJS comes
|
|
286
|
+
* pre-configured with strategies that address these issues, but for this to work backend server
|
|
287
|
+
* cooperation is required.
|
|
288
|
+
*
|
|
289
|
+
* ### JSON Vulnerability Protection
|
|
290
|
+
*
|
|
291
|
+
* A [JSON vulnerability](http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx)
|
|
292
|
+
* allows third party website to turn your JSON resource URL into
|
|
293
|
+
* [JSONP](http://en.wikipedia.org/wiki/JSONP) request under some conditions. To
|
|
294
|
+
* counter this your server can prefix all JSON requests with following string `")]}',\n"`.
|
|
295
|
+
* AngularJS will automatically strip the prefix before processing it as JSON.
|
|
296
|
+
*
|
|
297
|
+
* For example if your server needs to return:
|
|
298
|
+
*``js
|
|
299
|
+
_ ['one','two']
|
|
300
|
+
_ ` *
|
|
301
|
+
* which is vulnerable to attack, your server can return:
|
|
302
|
+
*`js
|
|
303
|
+
_ )]}',
|
|
304
|
+
_ ['one','two']
|
|
305
|
+
_ ```
|
|
306
|
+
_
|
|
307
|
+
_ AngularJS will strip the prefix, before processing the JSON.
|
|
308
|
+
_ \*
|
|
309
|
+
_ ### Cross Site Request Forgery (XSRF) Protection
|
|
310
|
+
_
|
|
311
|
+
_ [XSRF](http://en.wikipedia.org/wiki/Cross-site_request_forgery) is an attack technique by
|
|
312
|
+
_ which the attacker can trick an authenticated user into unknowingly executing actions on your
|
|
313
|
+
_ website. AngularJS provides a mechanism to counter XSRF. When performing XHR requests, the
|
|
314
|
+
_ $http service reads a token from a cookie (by default, `XSRF-TOKEN`) and sets it as an HTTP
|
|
315
|
+
_ header (by default `X-XSRF-TOKEN`). Since only JavaScript that runs on your domain could read
|
|
316
|
+
_ the cookie, your server can be assured that the XHR came from JavaScript running on your
|
|
317
|
+
_ domain.
|
|
318
|
+
_
|
|
319
|
+
_ To take advantage of this, your server needs to set a token in a JavaScript readable session
|
|
320
|
+
_ cookie called `XSRF-TOKEN` on the first HTTP GET request. On subsequent XHR requests the
|
|
321
|
+
_ server can verify that the cookie matches the `X-XSRF-TOKEN` HTTP header, and therefore be
|
|
322
|
+
_ sure that only JavaScript running on your domain could have sent the request. The token must
|
|
323
|
+
_ be unique for each user and must be verifiable by the server (to prevent the JavaScript from
|
|
324
|
+
_ making up its own tokens). We recommend that the token is a digest of your site's
|
|
325
|
+
_ authentication cookie with a [salt](https://en.wikipedia.org/wiki/Salt_(cryptography))
|
|
326
|
+
\_ for added security. \* \* The header will — by default — **not** be set for cross-domain requests. This
|
|
327
|
+
_ prevents unauthorized servers (e.g. malicious or compromised 3rd-party APIs) from gaining
|
|
328
|
+
_ access to your users' XSRF tokens and exposing them to Cross Site Request Forgery. If you
|
|
329
|
+
_ want to, you can trust additional origins to also receive the XSRF token, by adding them
|
|
330
|
+
_ to {@link ng.$httpProvider#xsrfTrustedOrigins xsrfTrustedOrigins}. This might be
|
|
331
|
+
* useful, for example, if your application, served from `example.com`, needs to access your API
|
|
332
|
+
* at `api.example.com`.
|
|
333
|
+
* See {@link ng.$httpProvider#xsrfTrustedOrigins $httpProvider.xsrfTrustedOrigins} for
|
|
334
|
+
_ more details.
|
|
335
|
+
_
|
|
336
|
+
_ <div class="alert alert-danger">
|
|
337
|
+
_ **Warning**<br />
|
|
338
|
+
_ Only trusted origins that you have control over and make sure you understand the
|
|
339
|
+
_ implications of doing so.
|
|
340
|
+
_ </div>
|
|
341
|
+
_
|
|
342
|
+
_ The name of the cookie and the header can be specified using the `xsrfCookieName` and
|
|
343
|
+
_ `xsrfHeaderName` properties of either `$httpProvider.defaults` at config-time,
|
|
344
|
+
_ `$http.defaults` at run-time, or the per-request config object.
|
|
345
|
+
_
|
|
346
|
+
_ In order to prevent collisions in environments where multiple AngularJS apps share the
|
|
347
|
+
_ same domain or subdomain, we recommend that each application uses a unique cookie name. \* \*
|
|
348
|
+
_ @param {object} requestConfig Object describing the request to be made and how it should be
|
|
349
|
+
_ processed. The object has following properties: \* \* - **method** – `{string}` – HTTP method (e.g. 'GET', 'POST', etc) \* - **url** – `{string|TrustedObject}` – Absolute or relative URL of the resource that is being requested;
|
|
350
|
+
_ or an object created by a call to `$sce.trustAsResourceUrl(url)`.
|
|
351
|
+
_ - **params** – `{Object.<string|Object>}` – Map of strings or objects which will be serialized
|
|
352
|
+
_ with the `paramSerializer` and appended as GET parameters.
|
|
353
|
+
_ - **data** – `{string|Object}` – Data to be sent as the request message data. \* - **headers** – `{Object}` – Map of strings or functions which return strings representing
|
|
354
|
+
_ HTTP headers to send to the server. If the return value of a function is null, the
|
|
355
|
+
_ header will not be sent. Functions accept a config object as an argument. \* - **eventHandlers** - `{Object}` - Event listeners to be bound to the XMLHttpRequest object.
|
|
356
|
+
_ To bind events to the XMLHttpRequest upload object, use `uploadEventHandlers`.
|
|
357
|
+
_ The handler will be called in the context of a `$apply` block. \* - **uploadEventHandlers** - `{Object}` - Event listeners to be bound to the XMLHttpRequest upload
|
|
358
|
+
_ object. To bind events to the XMLHttpRequest object, use `eventHandlers`.
|
|
359
|
+
_ The handler will be called in the context of a `$apply` block. \* - **xsrfHeaderName** – `{string}` – Name of HTTP header to populate with the XSRF token. \* - **xsrfCookieName** – `{string}` – Name of cookie containing the XSRF token. \* - **transformRequest** –
|
|
360
|
+
_ `{function(data, headersGetter)|Array.<function(data, headersGetter)>}` –
|
|
361
|
+
_ transform function or an array of such functions. The transform function takes the http
|
|
362
|
+
_ request body and headers and returns its transformed (typically serialized) version.
|
|
363
|
+
_ See {@link ng.$http#overriding-the-default-transformations-per-request
|
|
364
|
+
_ Overriding the Default Transformations}
|
|
365
|
+
_ - **transformResponse** –
|
|
366
|
+
_ `{function(data, headersGetter, status)|Array.<function(data, headersGetter, status)>}` –
|
|
367
|
+
_ transform function or an array of such functions. The transform function takes the http
|
|
368
|
+
_ response body, headers and status and returns its transformed (typically deserialized) version.
|
|
369
|
+
_ See {@link ng.$http#overriding-the-default-transformations-per-request
|
|
370
|
+
_ Overriding the Default Transformations}
|
|
371
|
+
_ - **paramSerializer** - `{string|function(Object<string,string>):string}` - A function used to
|
|
372
|
+
_ prepare the string representation of request parameters (specified as an object).
|
|
373
|
+
_ If specified as string, it is interpreted as function registered with the
|
|
374
|
+
_ {@link $injector $injector}, which means you can create your own serializer
|
|
375
|
+
_ by registering it as a {@link auto.$provide#service service}.
|
|
376
|
+
_ The default serializer is the {@link $httpParamSerializer $httpParamSerializer};
|
|
377
|
+
_ alternatively, you can use the {@link $httpParamSerializerJQLike $httpParamSerializerJQLike} \* - **cache** – `{boolean|Object}` – A boolean value or object created with
|
|
378
|
+
_ {@link ng.$cacheFactory `$cacheFactory`} to enable or disable caching of the HTTP response.
|
|
379
|
+
_ See {@link $http#caching $http Caching} for more information. \* - **timeout** – `{number|Promise}` – timeout in milliseconds, or {@link ng.$q promise}
|
|
380
|
+
* that should abort the request when resolved.
|
|
381
|
+
*
|
|
382
|
+
* A numerical timeout or a promise returned from {@link ng.$timeout $timeout}, will set
|
|
383
|
+
* the `xhrStatus` in the {@link $http#$http-returns response} to "timeout", and any other
|
|
384
|
+
_ resolved promise will set it to "abort", following standard XMLHttpRequest behavior.
|
|
385
|
+
_ \* - **withCredentials** - `{boolean}` - whether to set the `withCredentials` flag on the
|
|
386
|
+
_ XHR object. See [requests with credentials](https://developer.mozilla.org/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials)
|
|
387
|
+
_ for more information. \* - **responseType** - `{string}` - see
|
|
388
|
+
_ [XMLHttpRequest.responseType](https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest#xmlhttprequest-responsetype).
|
|
389
|
+
_
|
|
390
|
+
_ @returns {PromiseLike} A {@link ng.$q `Promise}` that will be resolved (request success)
|
|
391
|
+
_ or rejected (request failure) with a response object. \*
|
|
392
|
+
_ The response object has these properties:
|
|
393
|
+
_ \* - **data** – `{string|Object}` – The response body transformed with
|
|
394
|
+
_ the transform functions.
|
|
395
|
+
_ - **status** – `{number}` – HTTP status code of the response. \* - **headers** – `{function([headerName])}` – Header getter function. \* - **config** – `{Object}` – The configuration object that was used
|
|
396
|
+
_ to generate the request.
|
|
397
|
+
_ - **statusText** – `{string}` – HTTP status text of the response. \* - **xhrStatus\*_ – `{string}` – Status of the XMLHttpRequest
|
|
398
|
+
_ (`complete`, `error`, `timeout` or `abort`). \* \*
|
|
399
|
+
_ A response status code between 200 and 299 is considered a success status
|
|
400
|
+
_ and will result in the success callback being called. Any response status
|
|
401
|
+
_ code outside of that range is considered an error status and will result
|
|
402
|
+
_ in the error callback being called.
|
|
403
|
+
_ Also, status codes less than -1 are normalized to zero. -1 usually means
|
|
404
|
+
_ the request was aborted, e.g. using a `config.timeout`. More information
|
|
405
|
+
_ about the status might be available in the `xhrStatus` property.
|
|
406
|
+
_
|
|
407
|
+
_ Note that if the response is a redirect, XMLHttpRequest will transparently
|
|
408
|
+
_ follow it, meaning that the outcome (success or error) will be determined
|
|
409
|
+
_ by the final response status code.
|
|
410
|
+
_ \*
|
|
411
|
+
_ @property {Array.<Object>} pendingRequests Array of config objects for currently pending
|
|
412
|
+
_ requests. This is primarily meant to be used for debugging purposes. \*
|
|
413
|
+
\*/
|
|
@@ -7,39 +7,7 @@ import {
|
|
|
7
7
|
} from "../../shared/utils";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* @ngdoc service
|
|
11
|
-
* @name $xhrFactory
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* @description
|
|
15
|
-
* Factory function used to create XMLHttpRequest objects.
|
|
16
|
-
*
|
|
17
|
-
* Replace or decorate this service to create your own custom XMLHttpRequest objects.
|
|
18
|
-
*
|
|
19
|
-
* ```
|
|
20
|
-
* angular.module('myApp', [])
|
|
21
|
-
* .factory('$xhrFactory', function() {
|
|
22
|
-
* return function createXhr(method, url) {
|
|
23
|
-
* return new window.XMLHttpRequest({mozSystem: true});
|
|
24
|
-
* };
|
|
25
|
-
* });
|
|
26
|
-
* ```
|
|
27
|
-
*
|
|
28
|
-
* @param {string} method HTTP method of the request (GET, POST, PUT, ..)
|
|
29
|
-
* @param {string} url URL of the request.
|
|
30
|
-
*/
|
|
31
|
-
export function $xhrFactoryProvider() {
|
|
32
|
-
this.$get = () => {
|
|
33
|
-
return function createXhr() {
|
|
34
|
-
return new window.XMLHttpRequest();
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
10
|
|
|
39
|
-
/**
|
|
40
|
-
* @ngdoc service
|
|
41
|
-
* @name $httpBackend
|
|
42
|
-
* @requires $xhrFactory
|
|
43
11
|
*
|
|
44
12
|
*
|
|
45
13
|
* @description
|
|
@@ -53,14 +21,22 @@ export function $xhrFactoryProvider() {
|
|
|
53
21
|
export function $HttpBackendProvider() {
|
|
54
22
|
this.$get = [
|
|
55
23
|
"$browser",
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
24
|
+
/**
|
|
25
|
+
* @param {import('../browser').Browser} $browser
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
function ($browser) {
|
|
29
|
+
return createHttpBackend($browser, $browser.defer);
|
|
59
30
|
},
|
|
60
31
|
];
|
|
61
32
|
}
|
|
62
33
|
|
|
63
|
-
|
|
34
|
+
/**
|
|
35
|
+
* @param {import('../browser').Browser} $browser
|
|
36
|
+
* @param {*} $browserDefer
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
export function createHttpBackend($browser, $browserDefer) {
|
|
64
40
|
// TODO(vojta): fix the signature
|
|
65
41
|
return function (
|
|
66
42
|
method,
|
|
@@ -76,7 +52,7 @@ export function createHttpBackend($browser, createXhr, $browserDefer) {
|
|
|
76
52
|
) {
|
|
77
53
|
url = url || $browser.url();
|
|
78
54
|
|
|
79
|
-
|
|
55
|
+
const xhr = new XMLHttpRequest();
|
|
80
56
|
let abortedByTimeout = false;
|
|
81
57
|
|
|
82
58
|
xhr.open(method, url, true);
|
|
@@ -89,23 +65,23 @@ export function createHttpBackend($browser, createXhr, $browserDefer) {
|
|
|
89
65
|
xhr.onload = function () {
|
|
90
66
|
const statusText = xhr.statusText || "";
|
|
91
67
|
|
|
92
|
-
// responseText is the old-school way of retrieving response (supported by IE9)
|
|
93
|
-
// response/responseType properties were introduced in XHR Level2 spec (supported by IE10)
|
|
94
|
-
const response = "response" in xhr ? xhr.response : xhr.responseText;
|
|
95
|
-
|
|
96
68
|
let status = xhr.status;
|
|
97
69
|
|
|
98
70
|
// fix status code when it is 0 (0 status is undocumented).
|
|
99
71
|
// Occurs when accessing file resources or on Android 4.1 stock browser
|
|
100
72
|
// while retrieving files from application cache.
|
|
101
73
|
if (status === 0) {
|
|
102
|
-
status = response
|
|
74
|
+
status = xhr.response
|
|
75
|
+
? 200
|
|
76
|
+
: urlResolve(url).protocol === "file"
|
|
77
|
+
? 404
|
|
78
|
+
: 0;
|
|
103
79
|
}
|
|
104
80
|
|
|
105
81
|
completeRequest(
|
|
106
82
|
callback,
|
|
107
83
|
status,
|
|
108
|
-
response,
|
|
84
|
+
xhr.response,
|
|
109
85
|
xhr.getAllResponseHeaders(),
|
|
110
86
|
statusText,
|
|
111
87
|
"complete",
|
|
@@ -202,7 +178,6 @@ export function createHttpBackend($browser, createXhr, $browserDefer) {
|
|
|
202
178
|
if (isDefined(timeoutId)) {
|
|
203
179
|
$browser.cancel(timeoutId);
|
|
204
180
|
}
|
|
205
|
-
xhr = null;
|
|
206
181
|
|
|
207
182
|
callback(status, response, headersString, statusText, xhrStatus);
|
|
208
183
|
}
|
|
@@ -13,12 +13,8 @@ export function TemplateRequestProvider() {
|
|
|
13
13
|
var httpOptions;
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* @ngdoc method
|
|
17
|
-
* @name $templateRequestProvider#httpOptions
|
|
18
|
-
* @description
|
|
19
16
|
* The options to be passed to the {@link $http} service when making the request.
|
|
20
17
|
* You can use this to override options such as the "Accept" header for template requests.
|
|
21
|
-
*
|
|
22
18
|
* The {@link $templateRequest} will set the `cache` and the `transformResponse` properties of the
|
|
23
19
|
* options if not overridden here.
|
|
24
20
|
*
|
|
@@ -34,10 +30,6 @@ export function TemplateRequestProvider() {
|
|
|
34
30
|
};
|
|
35
31
|
|
|
36
32
|
/**
|
|
37
|
-
* @ngdoc service
|
|
38
|
-
* @name $templateRequest
|
|
39
|
-
*
|
|
40
|
-
* @description
|
|
41
33
|
* The `$templateRequest` service runs security checks then downloads the provided template using
|
|
42
34
|
* `$http` and, upon success, stores the contents inside of `$templateCache`. If the HTTP request
|
|
43
35
|
* fails or the response data of the HTTP request is empty, a `$compile` error will be thrown (the
|
|
@@ -54,7 +46,7 @@ export function TemplateRequestProvider() {
|
|
|
54
46
|
* 3rd party modules should use `$templateRequest` if their services or directives are loading
|
|
55
47
|
* templates.
|
|
56
48
|
*
|
|
57
|
-
* @param {string
|
|
49
|
+
* @param {string} tpl The HTTP request template URL
|
|
58
50
|
* @param {boolean=} ignoreRequestError Whether or not to ignore the exception when the request fails or the template is empty
|
|
59
51
|
*
|
|
60
52
|
* @return {Promise} a promise for the HTTP response data of the given URL.
|
|
@@ -15,68 +15,6 @@ import {
|
|
|
15
15
|
} from "../../shared/utils";
|
|
16
16
|
import { CACHE, EXPANDO } from "../../core/cache/cache";
|
|
17
17
|
|
|
18
|
-
/**
|
|
19
|
-
* Wraps a raw DOM element or HTML string as a [jQuery](http://jquery.com) element. Regardless of the presence of jQuery, `angular.element`
|
|
20
|
-
* delegates to AngularJS's built-in subset of jQuery, called "jQuery lite" or **jqLite**.
|
|
21
|
-
*
|
|
22
|
-
* JQLite is a tiny, API-compatible subset of jQuery that allows
|
|
23
|
-
* AngularJS to manipulate the DOM in a cross-browser compatible way. JQLite implements only the most
|
|
24
|
-
* commonly needed functionality with the goal of having a very small footprint.
|
|
25
|
-
*
|
|
26
|
-
* <div class="alert alert-info">**Note:** All element references in AngularJS are always wrapped with
|
|
27
|
-
* JQLite (such as the element argument in a directive's compile / link function). They are never raw DOM references.</div>
|
|
28
|
-
*
|
|
29
|
-
* <div class="alert alert-warning">**Note:** Keep in mind that this function will not find elements
|
|
30
|
-
* by tag name / CSS selector. For lookups by tag name, try instead `angular.element(document).find(...)`
|
|
31
|
-
* or `$document.find()`, or use the standard DOM APIs, e.g. `document.querySelectorAll()`.</div>
|
|
32
|
-
*
|
|
33
|
-
* ## AngularJS's JQLite
|
|
34
|
-
* JQLite provides only the following jQuery methods:
|
|
35
|
-
*
|
|
36
|
-
* - [`after()`](http://api.jquery.com/after/)
|
|
37
|
-
* - [`append()`](http://api.jquery.com/append/) - Contrary to jQuery, this doesn't clone elements
|
|
38
|
-
* so will not work correctly when invoked on a JQLite object containing more than one DOM node
|
|
39
|
-
* - [`attr()`](http://api.jquery.com/attr/) - Does not support functions as parameters
|
|
40
|
-
* - [`children()`](http://api.jquery.com/children/) - Does not support selectors
|
|
41
|
-
* - [`data()`](http://api.jquery.com/data/)
|
|
42
|
-
* - [`empty()`](http://api.jquery.com/empty/)
|
|
43
|
-
* - [`eq()`](http://api.jquery.com/eq/)
|
|
44
|
-
* - [`html()`](http://api.jquery.com/html/)
|
|
45
|
-
* - [`on()`](http://api.jquery.com/on/) - Does not support namespaces, selectors or eventData
|
|
46
|
-
* - [`off()`](http://api.jquery.com/off/) - Does not support namespaces, selectors or event object as parameter
|
|
47
|
-
* - [`parent()`](http://api.jquery.com/parent/) - Does not support selectors
|
|
48
|
-
* - [`prepend()`](http://api.jquery.com/prepend/)
|
|
49
|
-
* - [`remove()`](http://api.jquery.com/remove/)
|
|
50
|
-
* - [`removeData()`](http://api.jquery.com/removeData/)
|
|
51
|
-
* - [`replaceWith()`](http://api.jquery.com/replaceWith/)
|
|
52
|
-
* - [`text()`](http://api.jquery.com/text/)
|
|
53
|
-
* - [`val()`](http://api.jquery.com/val/)
|
|
54
|
-
*
|
|
55
|
-
* ## jQuery/jqLite Extras
|
|
56
|
-
* AngularJS also provides the following additional methods and events to both jQuery and JQLite:
|
|
57
|
-
*
|
|
58
|
-
* ### Events
|
|
59
|
-
* - `$destroy` - AngularJS intercepts all JQLite/jQuery's DOM destruction apis and fires this event
|
|
60
|
-
* on all DOM nodes being removed. This can be used to clean up any 3rd party bindings to the DOM
|
|
61
|
-
* element before it is removed.
|
|
62
|
-
*
|
|
63
|
-
* ### Methods
|
|
64
|
-
* - `controller(name)` - retrieves the controller of the current element or its parent. By default
|
|
65
|
-
* retrieves controller associated with the `ngController` directive. If `name` is provided as
|
|
66
|
-
* camelCase directive name, then the controller for this directive will be retrieved (e.g.
|
|
67
|
-
* `'ngModel'`).
|
|
68
|
-
* - `injector()` - retrieves the injector of the current element or its parent.
|
|
69
|
-
* - `scope()` - retrieves the {@link ng.$rootScope.Scope scope} of the current
|
|
70
|
-
* element or its parent. Requires {@link guide/production#disabling-debug-data Debug Data} to
|
|
71
|
-
* be enabled.
|
|
72
|
-
* - `isolateScope()` - retrieves an isolate {@link ng.$rootScope.Scope scope} if one is attached directly to the
|
|
73
|
-
* current element. This getter should be used only on elements that contain a directive which starts a new isolate
|
|
74
|
-
* scope. Calling `scope()` on this element always returns the original non-isolate scope.
|
|
75
|
-
* Requires {@link guide/production#disabling-debug-data Debug Data} to be enabled.
|
|
76
|
-
* - `inheritedData()` - same as `data()`, but walks up the DOM until a value is found or the top
|
|
77
|
-
* parent element is reached.
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
18
|
/** @type {number} */
|
|
81
19
|
let jqId = 1;
|
|
82
20
|
|
|
@@ -124,7 +62,7 @@ const BOOLEAN_ELEMENTS = {};
|
|
|
124
62
|
* JQLite both a function and an array-like data structure for manipulation of DOM, linking elements to expando cache,
|
|
125
63
|
* and execution of chain functions.
|
|
126
64
|
*
|
|
127
|
-
* @param {string|Node|JQLite|ArrayLike<Element>|(() => void)} element
|
|
65
|
+
* @param {string|Node|JQLite|ArrayLike<Element>|(() => void)|Window} element
|
|
128
66
|
* @returns {JQLite}
|
|
129
67
|
*/
|
|
130
68
|
export function JQLite(element) {
|
|
@@ -234,7 +172,7 @@ JQLite.prototype.controller = function (name) {
|
|
|
234
172
|
|
|
235
173
|
/**
|
|
236
174
|
* Return instance of injector attached to element
|
|
237
|
-
* @returns {import('../../
|
|
175
|
+
* @returns {import('../../core/di/internal-injector').InjectorService}
|
|
238
176
|
*/
|
|
239
177
|
JQLite.prototype.injector = function () {
|
|
240
178
|
return getInheritedData(this[0], "$injector");
|
|
@@ -560,7 +498,7 @@ JQLite.prototype.children = function () {
|
|
|
560
498
|
};
|
|
561
499
|
|
|
562
500
|
/**
|
|
563
|
-
* @param {string} node
|
|
501
|
+
* @param {string|JQLite} node
|
|
564
502
|
* @returns {JQLite}
|
|
565
503
|
*/
|
|
566
504
|
JQLite.prototype.append = function (node) {
|
|
@@ -742,10 +680,7 @@ JQLite.prototype.triggerHandler = function (event, extraParameters) {
|
|
|
742
680
|
};
|
|
743
681
|
for (let i = 0, ii = this.length; i < ii; i++) {
|
|
744
682
|
if (isUndefined(value)) {
|
|
745
|
-
|
|
746
|
-
if (isDefined(value)) {
|
|
747
|
-
value = JQLite(value);
|
|
748
|
-
}
|
|
683
|
+
fn(this[i], event, extraParameters);
|
|
749
684
|
} else {
|
|
750
685
|
addNodes(value, fn(this[i], event, extraParameters));
|
|
751
686
|
}
|