diff --git a/src/lib/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html b/src/lib/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html index 96a44ba313f..fb1893dcb1f 100644 --- a/src/lib/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html +++ b/src/lib/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.html @@ -3,9 +3,9 @@ #drawer class="sidenav" fixedInViewport="true" - [attr.role]="isHandset ? 'dialog' : 'navigation'" - [mode]="isHandset ? 'over' : 'side'" - [opened]="!isHandset"> + [attr.role]="(isHandset$ | async) ? 'dialog' : 'navigation'" + [mode]="(isHandset$ | async) ? 'over' : 'side'" + [opened]="!(isHandset$ | async)"> Menu Link 1 @@ -20,7 +20,7 @@ aria-label="Toggle sidenav" mat-icon-button (click)="drawer.toggle()" - *ngIf="isHandset"> + *ngIf="isHandset$ | async"> menu <%= project %> diff --git a/src/lib/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts b/src/lib/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts index d724892f0b2..6921eceb6b0 100644 --- a/src/lib/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts +++ b/src/lib/schematics/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts @@ -1,7 +1,7 @@ -import { Component, OnDestroy<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core'; +import { Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core'; import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout'; -import { Subject } from 'rxjs'; -import { takeUntil } from 'rxjs/operators'; +import { Observable } from 'rxjs'; +import { map } from 'rxjs/operators'; @Component({ selector: '<%= selector %>',<% if(inlineTemplate) { %> @@ -16,25 +16,13 @@ import { takeUntil } from 'rxjs/operators'; encapsulation: ViewEncapsulation.<%= viewEncapsulation %><% } if (changeDetection !== 'Default') { %>, changeDetection: ChangeDetectionStrategy.<%= changeDetection %><% } %> }) -export class <%= classify(name) %>Component implements OnDestroy { +export class <%= classify(name) %>Component { - isHandset: boolean; + isHandset$: Observable = this.breakpointObserver.observe(Breakpoints.Handset) + .pipe( + map(result => result.matches) + ); - /** Emits when the component is destroyed. */ - private readonly _destroyed = new Subject(); - - constructor(breakpointObserver: BreakpointObserver) { - breakpointObserver.observe(Breakpoints.Handset) - .pipe( - takeUntil(this._destroyed) - ).subscribe(result => { - this.isHandset = result.matches; - }); - } - - ngOnDestroy() { - this._destroyed.next(); - this._destroyed.complete(); - } + constructor(private breakpointObserver: BreakpointObserver) {} }