Align navbar back button on right side

 ̄綄美尐妖づ 提交于 2019-12-23 22:17:28

问题


I'm developing an ionic app and I need to align the navbar back button on right side. The following is my code:

<ion-view title="Home" ng-controller="HomeCtrl" style="padding-top: 50px">
  <ion-nav-bar class="bar-balanced bar-dark">
    <ion-nav-back-button></ion-nav-back-button>
  </ion-nav-bar>
  <ion-content scroll="true">
    <ion-list>
      <ion-item ng-repeat="item in items" href="#/res/{{item}}">
        {{item.toUpperCase()}}
      </ion-item>
    </ion-list>
  </ion-content>
</ion-view>

And I've tried following code for aligning button using ion-nav-buttons:

<ion-view title="Home" ng-controller="HomeCtrl" style="padding-top: 50px">
  <ion-nav-bar class="bar-balanced bar-dark">
    <ion-nav-buttons side="right">
      <ion-nav-back-button></ion-nav-back-button>
    </ion-nav-buttons>
  </ion-nav-bar>
  <ion-content scroll="true">
    <ion-list>
      <ion-item ng-repeat="item in items" href="#/res/{{item}}">
        {{item.toUpperCase()}}
      </ion-item>
    </ion-list>
  </ion-content>
</ion-view>

But the above code throwing error like:

Error: [$compile:ctreq] Controller 'ionNavBar', required by directive 'ionNavBackButton', can't be found!
http://errors.angularjs.org/1.4.3/$compile/ctreq?p0=ionNavBar&p1=ionNavBackButton
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:13380:12
    at getControllers (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21319:19)
    at nodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21445:33)
    at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20853:13)
    at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20857:13)
    at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20857:13)
    at nodeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:21457:24)
    at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20853:13)
    at compositeLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20857:13)
    at publicLinkFn (http://localhost:8100/lib/ionic/js/ionic.bundle.js:20728:30) <ion-nav-bar class="bar-balanced bar-dark nav-bar-container" nav-bar-transition="ios">(anonymous function) @ ionic.bundle.js:25642
ionic.bundle.js:1173 'webkitMovementX' is deprecated. Please use 'movementX' instead.

回答1:


You can use this code:

<ion-nav-buttons side="right">
    <button class="button button-icon button-clear ion-arrow-left-c" ng-click="goBack()">back
    </button>
</ion-nav-buttons>

and in your controller(s):

$scope.goBack = function() {
  $ionicHistory.goBack(-1);
}

P.S.: in this case no <ion-nav-back-button></ion-nav-back-button> is used

Here is an example: http://codepen.io/beaver71/pen/NNWZBp



来源:https://stackoverflow.com/questions/35693041/align-navbar-back-button-on-right-side

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!