你好,我是新來的離子在我的應用程序,我想要做的是改變基於用戶頁面的應用程序頁面的標題。例如,如果用戶在主頁上,應該說首頁如果他們在另一個頁面上,應該說另一個在頂部。在導航欄中更改標題來自Ctrl
每個頁面都有它自己的控制器,我創造了我稱爲AppCtrl
應用父控制器,並把上窗格:
<ion-pane ng-controller="AppCtrl">
</ion-pane>
這是我AppCtrl:
// Root Controller
.controller("AppCtrl", function($rootScope, $scope) {
// Adding Sum Property To Array Prototype
Array.prototype.sum = function (prop) {
var total = 0
for (var i = 0, _len = this.length; i < _len; i++) {
total += this[i][prop]
}
return total
}
$scope.title = {
name: '',
icon: ''
};
// Function To Change Pane Title
$rootScope.changeTitle = function(name, icon) {
$rootScope.title = {
name: name,
icon: icon
};
$rootScope.$broadcast('TITLE_UPDATED', $rootScope.title);
}
$scope.$on('TITLE_UPDATED', function(event, title) {
$scope.title = {
name: title.name,
icon: title.icon
};
})
})
這是我的主頁控制器:
// Home View Controller
.controller("HomeCtrl", function($scope, $rootScope) {
// Setting Title
$scope.changeTitle('Home', 'ion-home');
})
這是我的index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
<title></title>
<!-- compiled css output -->
<link href="css/ionic.app.css" rel="stylesheet">
<!-- custom css styles -->
<link href="css/style.css" rel="stylesheet">
<!-- ionic/angularjs js -->
<script src="lib/ionic/js/ionic.bundle.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
<!-- your app's js -->
<script src="js/app.js"></script>
<script src="js/app.ctrls.js"></script>
</head>
<body ng-app="mtgh">
<ion-pane ng-controller="AppCtrl">
<!-- </header + navbar> -->
<ion-side-menus enable-menu-with-back-views="false">
<ion-side-menu-content>
<ion-nav-bar class="bar-stable bar-header-shadow has-header">
<ion-nav-back-button>
</ion-nav-back-button>
<ion-nav-buttons side="left">
<button class="button button-icon button-clear ion-navicon" menu-toggle="left">
</button>
<h1 class="title">
<i class="{{ title.icon }}"></i> {{ title.name }}
</h1>
</ion-nav-buttons>
</ion-nav-bar>
<ion-nav-view name="content">
</ion-nav-view>
</ion-side-menu-content>
<h1 class="title">
<img src="img/logo-94x35.png" alt="Starter" title="Starter">
</h1>
<ion-side-menu side="left">
<ion-header-bar class="bar-stable">
<h1 class="title">
<img src="img/logo-94x35.png" alt="Starter" title="Starter">
</h1>
</ion-header-bar>
<ion-content>
<ion-list>
<ion-item menu-close="" ng-click="login()">
Login
</ion-item>
<ion-item menu-close="" href="#/app/search">
Search
</ion-item>
<ion-item menu-close="" href="#/app/browse">
Browse
</ion-item>
<ion-item menu-close="" href="#/app/playlists">
Playlists
</ion-item>
</ion-list>
</ion-content>
</ion-side-menu>
</ion-side-menus>
<!-- </header> -->
<!-- <footer> -->
<ion-footer-bar class="bar-stable">
<h1 class="title">Starter</h1>
</ion-footer-bar>
<!-- </footer> -->
</ion-pane>
</body>
</html>
做什麼?我將如何使用它? – user3718908
我想設置一個不使用狀態或位置名稱/路徑的自定義名稱。 – user3718908
我沒有看到任何內容,它允許我爲我的頁面設置自定義標題。 – user3718908