如果我回到主頁選項卡,每次如何獲得新的http響應?如何在輸入AngularJS的每個頁面上調用http請求?
我嘗試了幾件事。我讀了「$ state.reload()」,但我不知道在哪裏使用它。 ng-click在tabs.html中不起作用。
控制器:
.controller('HomeCtrl', function ($scope, $http) {
'use strict';
// how to call this every time on coming back to this tab?
$http.get("api.php")
.then(function successCallback(response) {
$scope.plan = response.data;
}, function errorCallback(response) {
console.error("Failed HTTP get: " + response.status + " " + response.data);
});
// ...
tabs.html
<ion-tabs>
<ion-tab title="Home" href="#/tab/home">
<ion-nav-view name="tab-home"></ion-nav-view>
</ion-tab>
<!-- ... -->
</ion-tabs>
的index.html:
<ion-nav-view></ion-nav-view>
模塊:
.config(function ($stateProvider, $urlRouterProvider) {
$stateProvider
.state('tab', {
url: '/tab',
abstract: true,
templateUrl: 'templates/tabs.html'
})
.state('tab.home', {
url: '/home',
views: {
'tab-home': {
templateUrl: 'templates/tab-home.html',
controller: 'HomeCtrl'
}
}
})
非常感謝!
查看'angular.run',並在那裏訂閱'stateChangeStart',在那裏發出請求。 –