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' ;
22import { 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