[英]How to give responsive title in ion-header-bar in ionic framework based on selected page?
In header bar I need title to change dynamically according to current page app is on. 在标题栏中,我需要根据当前打开的页面应用程序动态更改标题。 It can be achieved using ion-nav-bar but I also need my custom controls on bar along with fixed header bar for all pages. 可以使用ion-nav-bar来实现,但是我还需要在bar上使用自定义控件以及所有页面的固定标题栏。
So in {{pageTitle}} variable is used for title attribute in header bar, I want to know where and how or in which controller can I create and update this variable, so change is reflected whenever page is navigated? 因此,在{{pageTitle}}变量用于标题栏中的标题属性时,我想知道可以在何处以及如何或在哪个控制器中创建和更新此变量,因此无论何时浏览页面,更改都会反映出来?
<ion-header-bar align-title="left" class="bar-positive"> <div class="buttons"> <button class="button" ng-click="doSomething()">Left Button</button> </div> <h1 class="title">{{pageTitle}}</h1> <div class="buttons"> <button class="button">Right Button</button> </div> </ion-header-bar> <ion-content> Some content! </ion-content>
You can define variable pageTitle
in $rootScope
: 您可以在$rootScope
定义变量pageTitle
:
angular.module('your_app_name', [])
.run(funtion($rootScope) {
$rootScope.pageTitle = 'Something initial';
});
and change $rootScope.pageTitle
in template's controller whenever you need change page title: 并在需要更改页面标题时在模板的控制器中更改$rootScope.pageTitle
:
angular.module('your_app_name')
.controller('SomeCtrl', function($rootScope) {
$rootScope.pageTitle = 'Another Title';
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.