Skip to content

Commit c868f40

Browse files
committed
docs(http): improve docs for Headers
1 parent 17af481 commit c868f40

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

modules/angular2/src/http/headers.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,29 @@ import {
1010

1111
/**
1212
* Polyfill for [Headers](https://developer.mozilla.org/en-US/docs/Web/API/Headers/Headers), as
13-
* specified in the [Fetch Spec](https://fetch.spec.whatwg.org/#headers-class). The only known
14-
* difference from the spec is the lack of an `entries` method.
13+
* specified in the [Fetch Spec](https://fetch.spec.whatwg.org/#headers-class).
14+
*
15+
* The only known difference between this `Headers` implementation and the spec is the
16+
* lack of an `entries` method.
17+
*
18+
* ### Example ([live demo](http://plnkr.co/edit/MTdwT6?p=preview))
19+
*
20+
* ```
21+
* import {Headers} from 'angular2/http';
22+
*
23+
* var firstHeaders = new Headers();
24+
* firstHeaders.append('Content-Type', 'image/jpeg');
25+
* console.log(firstHeaders.get('Content-Type')) //'image/jpeg'
26+
*
27+
* // Create headers from Plain Old JavaScript Object
28+
* var secondHeaders = new Headers({
29+
* 'X-My-Custom-Header': 'Angular'
30+
* });
31+
* console.log(secondHeaders.get('X-My-Custom-Header')); //'Angular'
32+
*
33+
* var thirdHeaders = new Headers(secondHeaders);
34+
* console.log(thirdHeaders.get('X-My-Custom-Header')); //'Angular'
35+
* ```
1536
*/
1637
export class Headers {
1738
_headersMap: Map<string, string[]>;
@@ -50,7 +71,9 @@ export class Headers {
5071
*/
5172
delete (name: string): void { MapWrapper.delete(this._headersMap, name); }
5273

53-
forEach(fn: Function) { MapWrapper.forEach(this._headersMap, fn); }
74+
forEach(fn: (value: string, name: string, headers: Headers) => any): void {
75+
MapWrapper.forEach(this._headersMap, fn);
76+
}
5477

5578
/**
5679
* Returns first header that matches given name.

0 commit comments

Comments
 (0)