Commit Graph

268 Commits

Author SHA1 Message Date
Ahmed Ayed e05a6f3bb3 feat(common): add `historyGo` method to `Location` service (#38890)
Add new method `historyGo`, that will let
the user navigate to a specific page from session history identified by its
relative position to the current page.

We add some tests to `location_spec.ts` to validate the behavior of the
`historyGo` and `forward` methods.

Add more tests for `location_spec` to test `location.historyGo(0)`, `location.historyGo()`,
`location.historyGo(100)` and `location.historyGo(-100)`. We also add new tests for
`Integration` spec to validate the navigation when we using
`location#historyGo`.

Update the `historyGo` function docs

Note that this was made an optional function in the abstract classes to
avoid a breaking change. Because our location classes use `implements PlatformLocation`
rather than `extends PlatformLocation`, simply adding a default
implementation was not sufficient to make this a non-breaking change.
While we could fix the classes internal to Angular, this would still have been
a breaking change for any external developers who may have followed our
implementations as an example.

PR Close #38890
2021-04-06 09:25:58 -07:00
Alan Agius e0028e5741 fix(platform-browser): configure `XhrFactory` to use `BrowserXhr` (#41313)
With this change we move `XhrFactory` to the root entrypoint of `@angular/commmon`, this is needed so that we can configure `XhrFactory` DI token at a platform level, and not add a dependency  between `@angular/platform-browser` and `@angular/common/http`.

Currently, when using `HttpClientModule` in a child module on the server, `ReferenceError: XMLHttpRequest is not defined` is being thrown because the child module has its own Injector and causes `XhrFactory` provider to be configured to use `BrowserXhr`.
Therefore, we should configure the `XhrFactory` at a platform level similar to other Browser specific providers.

BREAKING CHANGE:

`XhrFactory` has been moved from `@angular/common/http` to `@angular/common`.

**Before**
```ts
import {XhrFactory} from '@angular/common/http';
```

**After**
```ts
import {XhrFactory} from '@angular/common';
```

Closes #41311

PR Close #41313
2021-03-29 15:14:16 -07:00
Kristiyan Kostadinov 3c66b100dd perf(common): remove unused methods from DomAdapter (#41102)
The `DomAdapter` is present in all Angular apps and its methods aren't tree shakeable.
These changes remove the methods that either aren't being used anymore or were only
used by our own tests. Note that these changes aren't breaking, because the adapter
is an internal API.

The following methods were removed:
* `getProperty` - only used within our own tests.
* `log` - Guaranteed to be defined on `console`.
* `logGroup` and `logGroupEnd` - Only used in one place. It was in the DomAdapter for built-in null checking.
* `logGroupEnd` - Only used in one place. It was placed in the DomAdapter for built in null checking.
* `performanceNow` - Only used in one place that has to be invoked through the browser console.
* `supportsCookies` - Unused.
* `getCookie` - Unused.
* `getLocation` and `getHistory` - Only used in one place which appears to have access to the DOM
already, because it had direct accesses to `window`. Furthermore, even if this was being used
in a non-browser context already, the `DominoAdapter` was set up to throw an error.

The following APIs were changed to be more compact:
* `supportsDOMEvents` - Changed to a readonly property.
* `remove` - No longer returns the removed node.

PR Close #41102
2021-03-10 11:48:24 -08:00
Theoklitos Bampouris e29a29ce9f docs(common): change misspelled constant (#41136)
Change misspelled constant from LOCAL_ID to LOCALE_ID
PR Close #41136
2021-03-09 08:57:38 -08:00
Igor Minar 03d47d5701 feat(core): manually annotate de-sugarred core tree-shakable providers with @pureOrBreakMyCode (#41096)
This is necessary for closure compiler in order to support cross chunk code motion.

I'm intentionally not annotating these call sites with @__PURE__ at the moment because
build-optimizer does it within the Angular CLI build. In the future we might want to consider
having both annotations here in case we change how build-optimizer works.

PR Close #41096
2021-03-08 10:30:08 -08:00
Quentin Monmert c676ec1ce5 docs: fix some typos in angular.io examples (#41093)
This commit updates example code to make the spacing more consistent.

PR Close #41093
2021-03-05 15:08:11 -08:00
arturovt 38524c4d29 fix(common): cleanup location change listeners when the root view is removed (#40867)
In the new behavior Angular cleanups `popstate` and `hashchange` event listeners
when the root view gets destroyed, thus event handlers are not added twice
when the application is bootstrapped again.

BREAKING CHANGE:

Methods of the `PlatformLocation` class, namely `onPopState` and `onHashChange`,
used to return `void`. Now those methods return functions that can be called
to remove event handlers.

PR Close #31546

PR Close #40867
2021-03-04 13:09:04 -08:00
Kapunahele Wong 6c783c7fcb docs: rewrite structural-directives.md (#40015)
PR Close #40015
2021-03-01 15:32:26 -08:00
Chris bebdeba5fd docs: improve description, examples of DecimalPipe's digitsInfo parameter (#40714)
Fixes #40671

PR Close #40714
2021-02-26 15:42:29 -08:00
Kristiyan Kostadinov d3705b3284 fix(common): avoid mutating context object in NgTemplateOutlet (#40360)
Currently `NgTemplateOutlet` recreates its view if its template is swapped out or a context
object with a different shape is passed in. If an object with the same shape is passed in,
we preserve the old view and we mutate the previous object. This mutation of the original
object can be undesirable if two objects with the same shape are swapped between two
different template outlets.

The current behavior is a result of a limitation in `core` where the `context` of an embedded
view is read-only, however a previous commit made it writeable.

These changes resolve the context mutation issue and clean up a bunch of unnecessary
logic from `NgTemplateOutlet` by taking advantage of the earlier change.

Fixes #24515.

PR Close #40360
2021-02-23 08:14:02 -08:00
kirjs c56ecab515 feat(common): support ICU standard "stand alone day of week" with `DatePipe` (#40766)
This commit adds support for Finnish full date formatting,
as well as `c/cc/ccc/cccc/ccccc/cccccc` date formats in the `DatePipe`.

Fixes #26922

PR Close #40766
2021-02-10 16:03:06 -08:00
Alexey Elin ddff6b63d7 docs: fix absent documentation for digitsInfo parameter in the API docs (#40746)
PR Close #40746
2021-02-10 11:09:09 -08:00
abarghoud 03f0b157c1 fix(common): date is not correctly formatted when year is between 0 and 99 (#40448)
use setFullYear method when parsing date to avoid javascript date factory behaviour

Fixes #40377

PR Close #40448
2021-02-10 11:04:37 -08:00
Pete Bacon Darwin ca0f6e6eed fix(common): parse `YYYY` strings as UTC dates (#40629)
In b6cd38ff05 we fixed the DatePipe so
that when it parsed date strings that looked like `YYYY-MM` it created a UTC
date that was not affected by the local timezone of the JavaScript engine.

This commit does the same for date strings of the form `YYYY`.

(Note that the previous commit, mentioned above, attempted to fix this case
too but the test was not actually checking the correct input string.)

Fixes #33944

PR Close #40620

PR Close #40629
2021-01-29 11:14:05 -08:00
Pete Bacon Darwin b6cd38ff05 fix(common): parse `YYYY-MM` strings as UTC dates (#40620)
In 2aba8b0 we fixed the DatePipe so that when it parsed date strings
that looked like `YYYY-MM-DD` it created a UTC date that was not
affected by the local timezone of the JavaScript engine.

This commit does the same for date strings of the form `YYYY-MM`
and `YYYY`.

Fixes #33944

PR Close #40620
2021-01-28 16:00:57 -08:00
Alexey Elin cf02cf1e18 docs: remove duplicated the (#40434)
PR Close #40434
2021-01-14 11:33:57 -08:00
Andrew Scott 4eac7e6436 fix(router): Router should focus element after scrolling (#40241)
According to the [spec](https://html.spec.whatwg.org/#scroll-to-fragid),
we should attempt to set the browser focus after scrolling to a
fragment. Note that this change does not exactly follow the robust steps
outlined in the spec by finding a fallback target if the original is not
focusable. Instead, we simply attempt to focus the element by calling
`focus` on it, which will do nothing if the element is not focusable.

fixes #30067

PR Close #40241
2021-01-05 09:48:48 -08:00
Andrew Scott a55f581add refactor(router): Remove unused property in `BrowserViewportScroller` (#40241)
The `BrowserViewportScroller` injects but does not use the `ErrorHandler`.
This commit removes the `ErrorHandler` from the constructor.

PR Close #40241
2021-01-05 09:48:47 -08:00
Julien 42d478b16a docs(common): use table layout for Pre-defined format options (#40036)
easier to read
PR Close #40036
2020-12-09 09:11:03 -08:00
arturovt f022efa06f perf(common): use `ngDevMode` to tree-shake warnings (#39964)
This commit adds ngDevMode guard to show warnings only
in dev mode (similar to how things work in other parts of Ivy runtime code).
The ngDevMode flag helps to tree-shake these warnings from production builds
(in dev mode everything will work as it works right now) to decrease production bundle size.

PR Close #39964
2020-12-04 16:08:00 -08:00
Kapunahele Wong 2c275f6d7a docs: archive template expression operators doc, move pipes precedence section (#39170)
Archives most of the content in the template expression operators doc.
The pipes precedence section that was originally in
template expression operators moves into the pipes doc
with some editing and an addition of a ternary example.

PR Close #39170
2020-11-24 08:41:18 -08:00
David-Emmanuel DIVERNOIS c7f4abf18a feat(common): allow any Subscribable in async pipe (#39627)
As only methods from the Subscribable interface are currently used in the
implementation of the async pipe, it makes sense to make it explicit so
that it works successfully with any other implementation instead of
only Observable.

PR Close #39627
2020-11-23 08:28:11 -08:00
Marcono1234 3e1e5a15ba docs: update links to use HTTPS as protocol (#39718)
PR Close #39718
2020-11-20 12:52:16 -08:00
WilliamKoza b1d300dc26 fix(common): Prefer to use pageXOffset / pageYOffset instance of scrollX / scrollY (#28262)
This fix ensures a better cross-browser compatibility.
This fix has been used for angular.io.

PR Close #28262
2020-11-19 12:22:03 -08:00
Andrew Kushnir 4e68254514 fix(common): change the week-numbering year format from `r` -> `Y` (#39495)
This commit updates the week-numbering year format from `r` -> `Y` based on the description in
http://www.unicode.org/reports/tr35/tr35-dates.html#dfst-year.

Note: this is not a breaking change, since the week-numbering year format was introduced in
v11.0.0-next.3 (984ed39195)
and the major version that contains that change was not released yet.

PR Close #39495
2020-10-30 10:24:43 -07:00
Andrew Kushnir 8fd25d9614 docs: remove IE10 references from comments in the code (#39090)
PR Close #39090
2020-10-13 15:51:49 -07:00
Joey Perrott 93c3d8f9fd fix(platform-webworker): remove platform-webworker and platform-webworker-dynamic (#38846)
Remove @angular/platform-webworker and @angular/platform-webworker-dynamic
as they were deprecated in v8

BREAKING CHANGE: @angular/platform-webworker and @angular/platform-webworker-dynamic
have been removed as they were deprecated in v8

PR Close #38846
2020-09-30 09:13:59 -04:00
Andrea Canciani 4744c229db fix(common): correct typing and implementation of `SlicePipe` (#37447)
Even in the overloads, state that it can accept `null` and
`undefined`, in order to ensure easy composition with `async`.

Additionally, change the implementation to return `null` on an
`undefined` input, for consistency with other pipes.

BREAKING CHANGE:
The `slice` pipe now returns `null` for the `undefined` input value,
which is consistent with the behavior of most pipes. If you rely on
`undefined` being the result in that case, you now need to check for it
explicitly.

PR Close #37447
2020-09-28 12:23:33 -04:00
Andrea Canciani 4dfe0fa068 fix(common): correct and simplify typing of `KeyValuePipe` (#37447)
As shown in the tests, `KeyValuePipe.transform` can accept
`undefined`, in which case it always returns `null`.

Additionally, the typing for `string` keys can be made generic, so the
comparison function is only required to accept the relevant cases.

Finally, the typing for `number` records now shows that the comparison
function and the result entries will actually receive the string version
of the numeric keys, just as shown in the tests.

BREAKING CHANGE:
The typing of the `keyvalue` pipe has been fixed to report that for
input objects that have `number` keys, the result will contain the
string representation of the keys. This was already the case and the
code has simply been updated to reflect this. Please update the
consumers of the pipe output if they were relying on the incorrect
types. Note that this does not affect use cases where the input values
are `Map`s, so if you need to preserve `number`s, this is an effective
way.

PR Close #37447
2020-09-28 12:23:33 -04:00
Andrea Canciani 3b919ef10f fix(common): correct and simplify typing of I18nPluralPipe (#37447)
I18nPluralPipe can actually accept `null` and `undefined` (which are
convenient for composing it with the async pipe), but it is currently
typed to only accept `number`.

PR Close #37447
2020-09-28 12:23:32 -04:00
Andrea Canciani 7b2aac97df feat(common): stricter types for number pipes (#37447)
Make typing of number pipes stricter to catch some misuses (such as
passing an Observable or an array) at compile time.

BREAKING CHANGE:
The signatures of the number pipes now explicitly state which types are
accepted. This should only cause issues in corner cases, as any other
values would result in runtime exceptions.

PR Close #37447
2020-09-28 12:23:32 -04:00
Andrea Canciani daf8b7f100 feat(common): stricter types for DatePipe (#37447)
Make typing of DatePipe stricter to catch some misuses (such as passing
an Observable or an array) at compile time.

BREAKING CHANGE:
The signature of the `date` pipe now explicitly states which types are
accepted. This should only cause issues in corner cases, as any other
values would result in runtime exceptions.

PR Close #37447
2020-09-28 12:23:32 -04:00
Andrea Canciani 5f815c0565 fix(common): correct and simplify typing of AsyncPipe (#37447)
`AsyncPipe.transform` will never return `undefined`, even when passed
`undefined` in input, in contrast with what was declared in the
overloads.

Additionally the "actual" method signature can be updated to match the
most generic case, since the implementation does not rely on wrappers
anymore.

BREAKING CHANGE:
The async pipe no longer claims to return `undefined` for an input that
was typed as `undefined`. Note that the code actually returned `null` on
`undefined` inputs. In the unlikely case you were relying on this,
please fix the typing of the consumers of the pipe output.

PR Close #37447
2020-09-28 12:23:32 -04:00
Andrea Canciani c7d5555dfb fix(common): let case conversion pipes accept type unions with `null` (#36259) (#37447)
The old implementation of case conversion types can handle several
values which are not strings, but the signature did not reflect this.

The new one reports errors when falsy non-string inputs are given to
the pipe (such as `false` or `0`) and has a new signature which
instead reflects the behaviour on `null` and `undefined`.

Fixes #36259

BREAKING CHANGE:
The case conversion pipes no longer let falsy values through. They now
map both `null` and `undefined` to `null` and raise an exception on
invalid input (`0`, `false`, `NaN`) just like most "common pipes". If
your code required falsy values to pass through, you need to handle them
explicitly.

PR Close #37447
2020-09-28 12:23:32 -04:00
Prashant Tholia 984ed39195 feat(common): Add ISO week-numbering year formats support to formatDate (#38828)
Add ISO 8601 week-numbering year formats ('r', 'rr', 'rrr', 'rrrr') support for formatDate function.

Issue:https://github.com/angular/angular/issues/38739

PR Close #38828
2020-09-21 12:24:43 -07:00
Artem Halas 6acea54f62 fix(common): mark locale data arrays as readonly (#30397)
To discourage developers from mutating the arrays returned
from the following methods, their return types have been marked
as readonly.

* `getLocaleDayPeriods()`
* `getLocaleDayNames()`
* `getLocaleMonthNames()`
* `getLocaleEraNames()`

Fixes #27003

BREAKING CHANGE:
The locale data API has been marked as returning readonly arrays, rather
than mutable arrays, since these arrays are shared across calls to the
API. If you were mutating them (e.g. calling `sort()`, `push()`, `splice()`, etc)
then your code will not longer compile. If you need to mutate the array, you
should now take a copy (e.g. by calling `slice()`) and mutate the copy.

PR Close #30397
2020-09-10 15:35:30 -07:00
Ajit Singh 26f28200bf fix(common): do not round up fractions of a millisecond in `DatePipe` (#38009)
Currently, the `DatePipe` (via `formatDate()`) rounds fractions of a millisecond to the
nearest millisecond. This can cause dates that are less than a millisecond before midnight
to be incremented to the following day.

The [ECMAScript specification](https://www.ecma-international.org/ecma-262/5.1/#sec-15.9.1.11)
defines that `DateTime` milliseconds should always be rounded down, so that `999.9ms`
becomes `999ms`.

This change brings `formatDate()` and so `DatePipe` inline with the ECMAScript
specification.

Fixes #37989

BREAKING CHANGE:

When passing a date-time formatted string to the `DatePipe` in a format that contains
fractions of a millisecond, the milliseconds will now always be rounded down rather than
to the nearest millisecond.

Most applications will not be affected by this change. If this is not the desired behaviour
then consider pre-processing the string to round the millisecond part before passing
it to the `DatePipe`.

PR Close #38009
2020-09-10 10:55:37 -07:00
Andrea Balducci 723a9ff095 docs(common): Wrong parameter description on TrackBy (#38495)
Track By Function receive the T[index] data, not the node id.
TrackByFunction reference description has the same issue.
PR Close #38495
2020-08-18 10:08:44 -07:00
Andrew Scott 71079ce47e fix(common): Allow scrolling when browser supports scrollTo (#38468)
This commit fixes a regression from "fix(common): ensure
scrollRestoration is writable (#30630)" that caused scrolling to not
happen at all in browsers that do not support scroll restoration. The
issue was that `supportScrollRestoration` was updated to return `false`
if a browser did not have a writable `scrollRestoration`. However, the
previous behavior was that the function would return `true` if
`window.scrollTo` was defined. Every scrolling function in the
`ViewportScroller` used `supportScrollRestoration` and, with the update
in bb88c9fa3d, no scrolling would be
performed if a browser did not have writable `scrollRestoration` but
_did_ have `window.scrollTo`.

Note, that this failure was detected in the saucelabs tests. IE does not
support scroll restoration so IE tests were failing.

PR Close #38468
2020-08-14 11:41:22 -07:00
Alessandro 354e66efad refactor(common): use getElementById in ViewportScroller.scrollToAnchor (#30143)
This commit uses getElementById and getElementsByName when an anchor scroll happens,
to avoid escaping the anchor and wrapping the code in a try/catch block.

Related to #28960

PR Close #30143
2020-08-07 11:14:31 -07:00
marcvincenti bb88c9fa3d fix(common): ensure scrollRestoration is writable (#30630)
Some specialised browsers that do not support scroll restoration
(e.g. some web crawlers) do not allow `scrollRestoration` to be
writable.

We already sniff the browser to see if it has the `window.scrollTo`
method, so now we also check whether `window.history.scrollRestoration`
is writable too.

Fixes #30629

PR Close #30630
2020-08-05 16:13:15 -07:00
Andrew Scott 8effc83b92 docs(router): clarify how base href is used to construct targets (#38123)
The documentation is not clear on how the base href and APP_BASE_HREF are used. This commit
should help clarify more complicated use-cases beyond the most common one of just a '/'

PR Close #38123
2020-07-29 13:34:02 -07:00
Andrea Canciani 9c8bc4a239 fix(common): narrow `NgIf` context variables in template type checker (#36627)
When the `NgIf` directive is used in a template, its context variables
can be used to capture the bound value. This is sometimes used in
complex expressions, where the resulting value is captured in a
context variable. There's two syntax forms available:

1. Binding to `NgIfContext.ngIf` using the `as` syntax:
```html
<span *ngIf="enabled && user as u">{{u.name}}</span>
```

2. Binding to `NgIfContext.$implicit` using the `let` syntax:
```html
<span *ngIf="enabled && user; let u">{{u.name}}</span>
```

Because of the semantics of `ngIf`, it is known that the captured
context variable is truthy, however the template type checker
would not consider them as such and still report errors when
`strict` is enabled.

This commit updates `NgIf`'s context guard to make the types of the
context variables truthy, avoiding the issue.

Based on https://github.com/angular/angular/pull/35125

PR Close #36627
2020-07-29 10:30:44 -07:00
Ajit Singh 3373453736 feat(common): add ReadonlyMap in place of Map in keyValuePipe (#37311)
ReadonlyMap is a superset of Map, in keyValuePipe we do not change the value of the object so ReadonlyPipe Works right in this case and we can accomodate more types. To accomodate more types added ReadonlyMap in Key Value pipe.

Fixes #37308

PR Close #37311
2020-07-20 14:13:15 -07:00
Kapunahele Wong 5b31a0a294 docs: separate template syntax into multiple docs (#36954)
This is part of a re-factor of template syntax and
structure. The first phase breaks out template syntax
into multiple documents. The second phase will be
a rewrite of each doc.

Specifically, this PR does the following:

- Breaks sections of the current template syntax document each into their own page.
- Corrects the links to and from these new pages.
- Adds template syntax subsection to the left side NAV which contains all the new pages.
- Adds the new files to pullapprove.

PR Close #36954
2020-07-20 11:16:44 -07:00
Ajit Singh ef1fb6dee4 fix(common): date pipe gives wrong week number (#37632)
Date pipe is giving wrong week number when used with the date format 'w'. If first week(according to Iso)  has some days in previous year

Fixes #33961

PR Close #37632
2020-06-25 12:08:46 -07:00
Joey Perrott 1bc807c81a style(common): enforce format on newly included files (#36940)
Historically files to be formatted were added to a listing (via matchers)
to be included in formatting.  Instead, this change begins efforts to
instead include all files in format enforcement, relying instead on an
opt out methodology.

PR Close #36940
2020-06-12 15:06:41 -07:00
Lars Gyrup Brink Nielsen 7edb026619 fix(common): prevent duplicate URL change notifications (#37459)
Prevent duplicate notifications from being emitted when multiple URL change listeners are registered using SpyLocation#onUrlChange.

Use `@internal` annotation for the `_urlChangeSubscription` properties instead of the `private` access modifier. Otherwise, we get in trouble because of  `SpyLocation implements Location`.

PR Close #37459
2020-06-09 08:26:34 -07:00
Lars Gyrup Brink Nielsen 3569fdf451 fix(common): prevent duplicate URL change notifications (#37404)
Prevent duplicate notifications from being emitted when multiple URL change listeners are registered using Location#onUrlChange.

PR Close #37404
2020-06-04 16:45:06 -07:00
Joey Perrott d1ea1f4c7f build: update license headers to reference Google LLC (#37205)
Update the license headers throughout the repository to reference Google LLC
rather than Google Inc, for the required license headers.

PR Close #37205
2020-05-26 14:26:58 -04:00