Skip to content

Commit 621ddf7

Browse files
devversionandrewseguin
authored andcommitted
fix(schematics): navigation schematic not respecting breakpoints on initial render (#16788)
a6cdcfc added the `share()` operator to the `isHandset$` observable. This accidentally broke the initial rendering of the navigation as the view subscribes to the observable (through `async` pipe) after the initial value has been emitted. Meaning that `isHandset$ | async` expression always evaluates to `null` until the breakpoint changes. (cherry picked from commit 3205b31)
1 parent a9d8f8c commit 621ddf7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/material/schematics/ng-generate/nav/files/__path__/__name@dasherize@if-flat__/__name@dasherize__.component.ts.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component<% if(!!viewEncapsulation) { %>, ViewEncapsulation<% }%><% if(changeDetection !== 'Default') { %>, ChangeDetectionStrategy<% }%> } from '@angular/core';
22
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
33
import { Observable } from 'rxjs';
4-
import { map, share } from 'rxjs/operators';
4+
import { map, shareReplay } from 'rxjs/operators';
55

66
@Component({
77
selector: '<%= selector %>',<% if(inlineTemplate) { %>
@@ -21,7 +21,7 @@ export class <%= classify(name) %>Component {
2121
isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
2222
.pipe(
2323
map(result => result.matches),
24-
share()
24+
shareReplay()
2525
);
2626

2727
constructor(private breakpointObserver: BreakpointObserver) {}

0 commit comments

Comments
 (0)