GithubHelp home page GithubHelp logo

Comments (11)

ThomasBurleson avatar ThomasBurleson commented on May 14, 2024 4

So that is not currently possible. Only the Flex-Layout API understands the responsive aliases (e.g. .gt-md). But you can use an inject MatchMediaObservable; which allows you to be easily notified when a mediaQuery activates.

html, body, material-app, md-sidenav-container, .my-content {
  margin: 0;
  width: 100%;
  height: 100%;
}
<app>
     <responsive-sidenav>
        <div sidenav-content>
            Hello, I am a responsive sideNav component
       </div>
       <div  main-content>
           Hello, I am the primary, main content
       </div>
     </responsive-sidenav>
</app>

Now let's use multi-slot, content projection within our Responsive-Sidenav component:

@Component({  
   selector : 'responsive-sidenav',
   template : `
     <md-sidenav-container>
      <md-sidenav mode="side" [opened]="isOpen">
        <ng-content  select="[sidenav-content]">Projected Drawer Content</ng-content>
      </md-sidenav>    
      <div class="my-content">
        <ng-content  select="[main-content]">Main content</ng-content>
     </div>
    </md-sidenav-container>
`
})
export class ResponsiveSideNav implements OnDestroy {
   private var _subscription; 
   isOpen = true;
 
   constructor(@Inject(MatchMediaObservable) media$) {
      this._subscription = media$.subscribe(change:MediaChange) => {
          let isMobile = (change.alias == 'xs') || (change.alias == 'sm');
          this.isOpen = !isMobile;
      });
   }
 
  ngOnDestory() {
    this._subscription.unsubscribe();
  }
}

Demos

Also you can review the source to our online Demo App:

from flex-layout.

geelus avatar geelus commented on May 14, 2024 1

Sure, I will. thanks again for your great help.

from flex-layout.

geelus avatar geelus commented on May 14, 2024

You guys are awesome! Thank you very much for your rapid response. I didn't expect it to be this quick honestly. Thanks Thomas

from flex-layout.

ThomasBurleson avatar ThomasBurleson commented on May 14, 2024

@geelus - In the future, please post usage questions:

Note: the Gitter room is not yet available. Check back after X-mas.

from flex-layout.

ThomasBurleson avatar ThomasBurleson commented on May 14, 2024

Thx @geelus . Sorry, I just made some corrections to my sample code ^.

I did not build a Plunkr to verify ;-)

from flex-layout.

ThomasBurleson avatar ThomasBurleson commented on May 14, 2024

Here is a Link to the responsive code in the Demo-App source: https://github.com/angular/flex-layout/blob/master/src/demo-app/app/docs-layout-responsive/responsiveFlexDirective.demo.ts#L45

from flex-layout.

ThomasBurleson avatar ThomasBurleson commented on May 14, 2024

@geelus - np. Give us a shoutout on Twitter. 🤓

from flex-layout.

ThomasBurleson avatar ThomasBurleson commented on May 14, 2024

@geelus - I prepared a Responsive-SideNav Plunkr showing how to use the MatchMediaObservable... only to discover a major bug: see issue #65

The Plunkr ^ has a work around and shows have a sidenav is now responsive.

Thanks for posting this issue... it helped us make the library better!

from flex-layout.

geelus avatar geelus commented on May 14, 2024

@ThomasBurleson glad I could help. Yesterday I used your solution and it worked like a charm! I didn't notice the bug, maybe because I was so excited to see this working!

Merry Christmas and Happy new year!

from flex-layout.

joejordanbrown avatar joejordanbrown commented on May 14, 2024

@ThomasBurleson your example has a spelling mistake ngOnDestory

from flex-layout.

angular-automatic-lock-bot avatar angular-automatic-lock-bot commented on May 14, 2024

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.

from flex-layout.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.