【发布时间】:2016-07-23 11:24:54
【问题描述】:
如果我每次返回主页选项卡,如何获得新的 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,在那里提出请求。
标签: angularjs routes state reload