Search code examples
ionic-frameworkionic-view

<ion-footer-bar> ng directives and attributes work when footer-bar inside ion-content but


I have this ion-footer-barwhich works just fine inside the ion-content, the problem is it isn't sticked to bottom as a footer should be:

<ion-footer-bar class="foot-bar" ng-hide="isKeyboardOpen">
  <button class="button button-block btn-policy ion-ios-arrow-thin-right"
          ng-disabled="(!medsRefundForm.firstSubform.$valid && !MedsRefund.toggleChecked)
            || (MedsRefund.toggleChecked && !medsRefundForm.secondSubform.$valid)"
          ng-click="submit()"></button>
</ion-footer-bar>

So when I put it outside of ion-content it sticks to bottom but now the ng-directives don't work I believe it's because they aren't sharing the same scope.

I even tried adding the data, like explained in egghead video and in this commentary but it didn't work. I also added data.* to all present vars in BOTH the ion-contentand the ion-footer-bar such asisKeyboardOpen`, but that didn't fixed the problem.

<ion-footer-bar class="foot-bar" ng-hide="data.isKeyboardOpen">
  <button class="button button-block btn-policy ion-ios-arrow-thin-right"
          ng-disabled="(!data.medsRefundForm.firstSubform.$valid && !data.MedsRefund.toggleChecked)
            || (data.MedsRefund.toggleChecked && !data.medsRefundForm.secondSubform.$valid)"
          ng-click="submit()"></button>
</ion-footer-bar>

Solution

  • ion-footer-bar must be placed outside the content.
    If you're using <ion-nav-view> it has to be placed outside that.

    <ion-header-bar class="bar-stable">
      <h1 class="title">Header</h1>
    </ion-header-bar>
    
    <ion-nav-view>
      <ion-content>
        Your content here
      </ion-content>
    </ion-nav-view>
    
    <ion-footer-bar class="bar-assertive">
      <h1 class="title">Footer</h1>
    </ion-footer-bar>
    

    It seems that your problem is with your controller. What you can do is wrap your html with a <div> and define a controller there.

    <div ng-controller="mainCtrl">
    
        <ion-header-bar class="bar-stable">
          <h1 class="title">Header</h1>
        </ion-header-bar>
    
        <ion-nav-view>
          <ion-content>
            Your content here
          </ion-content>
        </ion-nav-view>
    
        <ion-footer-bar class="bar-assertive">
          <h1 class="title">Footer</h1>
        </ion-footer-bar>
    
    </div>
    

    and things should work just fine.

    You can check this working sample here, where I can show/hide the footer bar clicking the button in the content.