fix(aio): revert resize to HostListener; delete device svc#16143
fix(aio): revert resize to HostListener; delete device svc#16143wardbell wants to merge 1 commit intoangular:masterfrom
Conversation
|
The angular.io preview for 6c539976ad4e1cecb88472ddb555a1eefa2e659b is available here. |
Angular change detection bug -> no page update on resize.
Reverting to `@HostListener('window:resize', ['$event.target.innerWidth'])` cures it.
Delete DeviceService which no longer serves a purpose.
Adjusted affected AppComponent and LiveExample tests.
6c53997 to
06aef2d
Compare
| @@ -62,6 +51,8 @@ describe('LiveExampleComponent', () => { | |||
| liveExampleDe.nativeElement.liveExampleContent = liveExampleContent; | |||
|
|
|||
| fixture.detectChanges(); | |||
| } | ||
| } | ||
|
|
||
| onResize(width?: number) { |
There was a problem hiding this comment.
Couldn't you use @HostListener here? Would that work?
There was a problem hiding this comment.
No. I tried it. Angular does not activate that decorator on a service. :( I think it should but that would be a new feature.
|
I reduced the original issue to angular/zone.js#741, but I do agree with @gkalpak that the host listener solution is WAY cleaner. |
|
@wardbell , @IgorMinar , I just tried angular/aio, I think maybe the problem is angular/aio/package.json still use [email protected], after upgrade to [email protected], the problem is gone. Because in [email protected], window.onProperty is also patched by zone.js with this PR,angular/zone.js#687. |
|
@JiaLiPassion, angular/zone#687 still doesn't seem to patch |
|
@gkalpak , I just tried with the example here like this. <!DOCTYPE html>
<html>
<head>
<script src="./zone.js"></script>
<script>
Zone.current.fork({name: 'resize'}).run(function() {
window.onresize = function() {
console.log('Zone name is ', Zone.current.name);
}
});
</script>
</head>
<body>
</body>
</html>>The output is And I also tried angular/aio, and debug at DeviceService export class DeviceService {
// Show sidenav next to the main doc when display width on current device is greater than this.
readonly sideBySideWidth = 1032;
displayWidth = new ReplaySubject<number>(1);
constructor() {
if (window) {
window.onresize = () => this.onResize();
this.onResize();
} else {
// when no window, pretend the display is wide.
this.onResize(this.sideBySideWidth + 1);
}
}window.onresize is patched by zone.js and the Zone.current.name is Here is the screenshot. |
|
@JiaLiPassion, you are right. I assumed that In that case, upgrading to zone.js 0.8.5 should indeed solve the issue. |
|
@gkalpak , yes, it will loop all properties which starts with Please check it. Thanks! |
|
@JiaLiPassion great work! Thank you! We'll still go ahead with merge in this PR which simplifies our code greatly, but it's good to know that the newer version of zones doesn't suffer from this problem. |
|
@IgorMinar , sure, glad to help! |
|
That's not so easy. Host listeners need to be associated with host element.
Services don't have any element associated with them so I don't know how
this would work. Defaulting to window is not a good option.
…On Wed, Apr 19, 2017, 11:49 PM Ward Bell ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In aio/src/app/shared/device.service.ts
<#16143 (comment)>:
> - readonly sideBySideWidth = 1032;
-
- displayWidth = new ReplaySubject<number>(1);
-
- constructor() {
-
- if (window) {
- window.onresize = () => this.onResize();
- this.onResize();
- } else {
- // when no window, pretend the display is wide.
- this.onResize(this.sideBySideWidth + 1);
- }
- }
-
- onResize(width?: number) {
No. I tried it. Angular does not activate that decorator on a service. :(
I think it should but that would be a new feature.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#16143 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AANM6Dz-WP_zZ9fgpVpAan4GCBNR5Ec1ks5rxoFQgaJpZM4NBMVM>
.
|
…6143) Angular change detection bug -> no page update on resize. Reverting to `@HostListener('window:resize', ['$event.target.innerWidth'])` cures it. Delete DeviceService which no longer serves a purpose. Adjusted affected AppComponent and LiveExample tests. PR Close angular#16143
…6143) Angular change detection bug -> no page update on resize. Reverting to `@HostListener('window:resize', ['$event.target.innerWidth'])` cures it. Delete DeviceService which no longer serves a purpose. Adjusted affected AppComponent and LiveExample tests. PR Close angular#16143
|
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |

Angular change detection bug -> no page update on resize.
Reverting to
@HostListener('window:resize', ['$event.target.innerWidth'])cures it.Delete DeviceService which no longer serves a purpose.
Adjusted affected AppComponent and LiveExample tests.
To see bug, checkout the 2nd commit from PR #15887 (or any subsequent commit before this PR) and do the following:
Set a breakpoint in
AppComponent#onResizeThis will confirm that the event is caught and propagated via
DeviceServiceto the method. The value ofthis.isSideBySidebecomestrue, the template binding should trigger nav panels to appear. But they don't.ChangeDetectorRef.detectChanges()andsetTimeouttricks are fruitless.I gave up wondering why. Reversion to the following gives the expected behavior.
Project timeline dictates moving forward and leaving the lingering questions unanswered.
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x")