Javascript AngularJS状态负载上的负载数据
我在Angular.js应用程序中有一个页面,它执行http请求并用结果填充一些文本框 我使用以下命令导航到此页面:Javascript AngularJS状态负载上的负载数据,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,我在Angular.js应用程序中有一个页面,它执行http请求并用结果填充一些文本框 我使用以下命令导航到此页面: $state.go('utab.history'); 但当它进入页面时,所有文本框都是空白的,我目前正在使用Ionics ion Refresh: <ion-refresher pulling-text="Pull to refresh..." on-refresh="showappraisal()"> </ion-refresher>
$state.go('utab.history');
但当它进入页面时,所有文本框都是空白的,我目前正在使用Ionics ion Refresh:
<ion-refresher
pulling-text="Pull to refresh..."
on-refresh="showappraisal()">
</ion-refresher>
要调用控制器函数,然后填充所有文本框,但现在应用程序几乎完成了,我需要解决这个问题
我尝试过使用$rootScope.$emit(“CallParentMethod”,{})代码>就在$state.go('utab.history')之前
确实运行了这个函数,但同样,在我执行拉刷新之前,它不会填充文本框(即使它们调用相同的函数)
当加载utab.history时,是否有方法获取事件?我相信您的问题有点模糊。但如果我理解正确,你可以这样做:
您可以通过以下方式将数据发送到状态:
$state.go('myView', { myKey: myData });
并从中访问数据
$stateParams.myKey
此外,不要使用任何事件触发get请求事件,您可以使用$ionicView.beforeEnter
事件来了解何时加载页面(即使默认情况下Ionic中存在缓存)您可以在控制器的构造函数中调用showEvaluation()
:
angular.controller('myId', function(){
this.showappraisal = function() {
//logic to load data here
};
//this will do the call when the controller is created which should happen when the state is started
this.showappraisal();
});
在视图控制器中添加侦听器函数,并根据需要进行更改
app.controller("yourcontroller", ['$scope', '$ionicView', function($scope, $ionicView){
$scope.$on('$ionicView.afterEnter', function(e){
//You can call your functions
});
});
或
在从一个视图导航到另一个视图时,有很多事件可用
可用事件:
加载、输入、离开、预输入、预输入、预输入、后输入、后输出、卸载
为方便起见,您可以收听上述任何活动
参考:你可以查看这个。这对我有用
$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams
文件:
当我执行$state.go('utab.history')时,我不想发送数据;我希望能够在该控制器中运行函数。当前,如果该状态已打开,则它不会执行任何操作,只会将您带到页面。好的,那么,$ionicView.beforeEnter
将在每次加载页面时被调用,即使存在缓存。这正是我要找的,非常感谢没有问题。为了社区的利益,请接受我在StackOverflow中的回答:)我认为我们需要更多的代码来解决这个问题。比如如何准确地加载数据。您是指html页面还是状态?那么为什么要定义函数?在这种情况下,您可以直接在控制器中写入代码。代码被放入函数中,因为它可以被ion refresh
调用,以便根据用户的要求刷新数据。
$scope.$on('$stateChangeSuccess', function(event, toState, toParams, fromState, fromParams) {
if(toState == 'utab.history')
{
// do your stuff
}
});
$state.go($state.current, {}, {reload: true}); //second parameter is for $stateParams