Skip to content

Commit aea43eb

Browse files
authored
Revert "avoid multiple async calls (#13301)" (#13399)
This reverts commit 381c037.
1 parent 381c037 commit aea43eb

File tree

2 files changed

+13
-25
lines changed

2 files changed

+13
-25
lines changed

src/lib/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
#drawer
44
class="sidenav"
55
fixedInViewport="true"
6-
[attr.role]="isHandset ? 'dialog' : 'navigation'"
7-
[mode]="isHandset ? 'over' : 'side'"
8-
[opened]="!isHandset">
6+
[attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'"
7+
[mode]="(isHandset$ | async) ? 'over' : 'side'"
8+
[opened]="!(isHandset$ | async)">
99
<mat-toolbar>Menu</mat-toolbar>
1010
<mat-nav-list>
1111
<a mat-list-item href="#">Link 1</a>
@@ -20,7 +20,7 @@
2020
aria-label="Toggle sidenav"
2121
mat-icon-button
2222
(click)="drawer.toggle()"
23-
*ngIf="isHandset">
23+
*ngIf="isHandset$ | async">
2424
<mat-icon aria-label="Side nav toggle icon">menu</mat-icon>
2525
</button>
2626
<span><%= project %></span>
Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { Component, OnDestroy<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core';
1+
import { Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core';
22
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
3-
import { Subject } from 'rxjs';
4-
import { takeUntil } from 'rxjs/operators';
3+
import { Observable } from 'rxjs';
4+
import { map } from 'rxjs/operators';
55

66
@Component({
77
selector: '<%= selector %>',<% if(inlineTemplate) { %>
@@ -16,25 +16,13 @@ import { takeUntil } from 'rxjs/operators';
1616
encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>,
1717
changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %>
1818
})
19-
export class <%= classify(name) %>Component implements OnDestroy {
19+
export class <%= classify(name) %>Component {
2020

21-
isHandset: boolean;
21+
isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
22+
.pipe(
23+
map(result => result.matches)
24+
);
2225

23-
/** Emits when the component is destroyed. */
24-
private readonly _destroyed = new Subject<void>();
25-
26-
constructor(breakpointObserver: BreakpointObserver) {
27-
breakpointObserver.observe(Breakpoints.Handset)
28-
.pipe(
29-
takeUntil(this._destroyed)
30-
).subscribe(result => {
31-
this.isHandset = result.matches;
32-
});
33-
}
34-
35-
ngOnDestroy() {
36-
this._destroyed.next();
37-
this._destroyed.complete();
38-
}
26+
constructor(private breakpointObserver: BreakpointObserver) {}
3927

4028
}

0 commit comments

Comments
 (0)