angular-cn/modules/playground/src
Victor Berchet a755b715ed feat(router): introduce `ParamMap` to access parameters
The Router use the type `Params` for all of:
- position parameters,
- matrix parameters,
- query parameters.

`Params` is defined as follow `type Params = {[key: string]: any}`

Because parameters can either have single or multiple values, the type should
actually be `type Params = {[key: string]: string | string[]}`.

The client code often assumes that parameters have single values, as in the
following exemple:

```
class MyComponent {
sessionId: Observable<string>;

constructor(private route: ActivatedRoute) {}

ngOnInit() {
    this.sessionId = this.route
      .queryParams
      .map(params => params['session_id'] || 'None');
}
}

```

The problem here is that `params['session_id']` could be `string` or `string[]`
but the error is not caught at build time because of the `any` type.

Fixing the type as describe above would break the build because `sessionId`
would becomes an `Observable<string | string[]>`.

However the client code knows if it expects a single or multiple values. By
using the new `ParamMap` interface the user code can decide when it needs a
single value (calling `ParamMap.get(): string`) or multiple values (calling
`ParamMap.getAll(): string[]`).

The above exemple should be rewritten as:

```
class MyComponent {
sessionId: Observable<string>;

constructor(private route: ActivatedRoute) {}

ngOnInit() {
    this.sessionId = this.route
      .queryParamMap
      .map(paramMap => paramMap.get('session_id') || 'None');
}
}

```

Added APIs:
- `interface ParamMap`,
- `ActivatedRoute.paramMap: ParamMap`,
- `ActivatedRoute.queryParamMap: ParamMap`,
- `ActivatedRouteSnapshot.paramMap: ParamMap`,
- `ActivatedRouteSnapshot.queryParamMap: ParamMap`,
- `UrlSegment.parameterMap: ParamMap`
2017-03-20 09:19:32 -07:00
..
animate refactor(playground): make playground great again 2016-11-10 12:07:51 -08:00
async refactor(playground): make playground great again 2016-11-10 12:07:51 -08:00
benchpress chore: rename modules/examples to modules/playground 2015-10-18 11:48:43 +00:00
gestures refactor(playground): update gestures playground to use latest hammer.js 2016-10-31 14:43:04 -07:00
hello_world docs: branding fixes (#14132) 2017-01-27 15:03:11 -06:00
http fix(compiler): do not autoinclude components declared as entry points (#10898) 2016-08-19 15:59:50 -07:00
jsonp refactor(http): Removed deprecated HTTP_PROVIDERS and JSONP_PROVIDERS (#10864) 2016-08-17 07:43:31 -07:00
key_events refactor(playground): make playground great again 2016-11-10 12:07:51 -08:00
model_driven_forms refactor(lint): Don't allow console.log 2016-11-23 15:47:01 -08:00
order_management docs: branding fixes (#14132) 2017-01-27 15:03:11 -06:00
person_management docs: branding fixes (#14132) 2017-01-27 15:03:11 -06:00
relative_assets test: fix existing tests by removing usage of obsolete stuff like component level directives, AsyncCompleter and TestComponentBuilder 2016-08-23 09:59:00 -07:00
routing feat(router): introduce `ParamMap` to access parameters 2017-03-20 09:19:32 -07:00
sourcemap fix(errors): [2/2] Rename Exception to Error; remove from public API 2016-08-26 10:37:17 -07:00
svg fix(compiler): do not autoinclude components declared as entry points (#10898) 2016-08-19 15:59:50 -07:00
template_driven_forms refactor(lint): Don't allow console.log 2016-11-23 15:47:01 -08:00
todo docs: branding fixes (#14132) 2017-01-27 15:03:11 -06:00
upgrade refactor(playground): make playground great again 2016-11-10 12:07:51 -08:00
web_workers fix(router): do not finish bootstrap until all the routes are resolved (#14762) 2017-03-07 14:27:20 -08:00
zippy_component docs: branding fixes (#14132) 2017-01-27 15:03:11 -06:00
bootstrap.ts refactor(animations): support browser animation rendering (#14578) 2017-02-22 15:14:49 -08:00