Flex-layout: Utilizing the Responsive API to manage container height

Created on 4 Jan 2017  路  8Comments  路  Source: angular/flex-layout

Is there a way to use the responsive API to set the height of a container?
At the moment I manage the height of the container like this:

section {
  height: 680px;
  @include xs {
    height: 100vh;
  }
}
<section id="s1" fxLayoutAlign="center">
  <img src="../assets/logo.svg" alt="Logo">
</section>

Most helpful comment

@cschroeter - you could also do it this way:

<section [ngStyle]="{'height':  media.isActive('xs') ? '100vh' : '680px' }">
</section>
export class MyComponentWithSections {
  constructor(@Inject(MatchMediaObservable) private media) { }  
}

All 8 comments

@cschroeter - At the moment, the only thing you can do is use the * MatchMediaObservable* to subscribe to the breakpoint activations and then set a class dynamically.

See:

<section [ngStyle]="{'height': sectionHeight}">
</section>
export class MyComponentWithSections {
  private _watcher : Subscription;
  public sectionHeight = "680px";

  constructor(@Inject(MatchMediaObservable) private _media$) {
    // Watch for breakpoint activations
    this._watcher = this._media$
        .subscribe((e:MediaChange) => {
            this.sectionHeight = (e.mqAlias == 'xs') ? "100vh" : "680px";
        });
  })

  ngOnDestroy() {
    this._watcher.unsubscribe();
  }

}

@cschroeter - you could also do it this way:

<section [ngStyle]="{'height':  media.isActive('xs') ? '100vh' : '680px' }">
</section>
export class MyComponentWithSections {
  constructor(@Inject(MatchMediaObservable) private media) { }  
}

Thank you @ThomasBurleson

Hi
Can you please tell me in what build I can use your solution?
I have "@angular/material": "2.0.0-beta.1" and it looks like your solution doesn't work there.
Thank you!

@dimabutenko it's not angular/material, you need flex-layout.

You can go to https://gitter.im/angular/flex-layout to get some more help about that :)

@maxime1992 it's my mistake.
I have "@angular/flex-layout": "2.0.0-beta.1"

@dimabutenko I also have that version and it's working well.

You can find the project I'm working on here and the specific file where I'm using that here.

Maybe it might help you :+1:

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

drew-moore picture drew-moore  路  4Comments

spottedmahn picture spottedmahn  路  5Comments

nueko picture nueko  路  5Comments

mackelito picture mackelito  路  4Comments

Pikachews picture Pikachews  路  4Comments