Can';t更新关于ajax成功的ion幻灯片
更新ionic framework幻灯片时遇到问题。我把a放在一起,它是当前的形式,不起作用,但是,你可以在那里看到代码 我的问题是,如果仅出于测试目的,我在加载页面时使用ajax,那么它就可以正常工作。如果我使用超时来模拟异步性,它也可以工作 如果我在ngSubmit上设置了一个函数,幻灯片不会更新,但是ajax的成功部分会检索数据。我也可以在html端打印,但幻灯片不会更新 谁能告诉我为什么 HTML: JavaScript,即在没有提交的情况下工作:Can';t更新关于ajax成功的ion幻灯片,ajax,angularjs,angularjs-ng-repeat,ionic-framework,Ajax,Angularjs,Angularjs Ng Repeat,Ionic Framework,更新ionic framework幻灯片时遇到问题。我把a放在一起,它是当前的形式,不起作用,但是,你可以在那里看到代码 我的问题是,如果仅出于测试目的,我在加载页面时使用ajax,那么它就可以正常工作。如果我使用超时来模拟异步性,它也可以工作 如果我在ngSubmit上设置了一个函数,幻灯片不会更新,但是ajax的成功部分会检索数据。我也可以在html端打印,但幻灯片不会更新 谁能告诉我为什么 HTML: JavaScript,即在没有提交的情况下工作: engine.module.contr
engine.module.controller('UserSearchCtrl', function($scope, $rootScope, $http, $ionicSlideBoxDelegate, $timeout, $state, $stateParams, $db, $user) {
$ionicSlideBoxDelegate.enableSlide(false);
$scope.width = window.outerWidth;
//$scope.retrieveResults = function() {
var token = $rootScope.user.token;
if ($scope.criteria !== '') {
$http.get(engine.config.REMOTE_URL + '/search?' + 'token=' + token)
.success(function(response) {
$scope.result = response.data;
$ionicSlideBoxDelegate.enableSlide(true);
$ionicSlideBoxDelegate.update();
})
} else {
// ALERT: criteria is not set
}
//};
});
更新
如果我在单击时调用该函数,它也可以工作。似乎只有在submit调用更新它的函数时幻灯片才起作用。因为它是异步的,所以我认为您的$ionicSlideBoxDelegate不再与控制器中的相同。您可以执行以下操作:
engine.module.controller('UserSearchCtrl', function($scope, $rootScope, $http, $ionicSlideBoxDelegate, $timeout, $state, $stateParams, $db, $user) {
var currentIonicSlideBoxDelegate = $ionicSlideBoxDelegate;
currentIonicSlideBoxDelegate.enableSlide(false);
$scope.width = window.outerWidth;
// if I wrap the below ajax fn in a function, called on submit, it stops working
$scope.retrieveResults = function() {
var token = $rootScope.user.token;
if ($scope.criteria !== '') {
$http.get(engine.config.REMOTE_URL + '/search?' + 'token=' + token)
.error(function(err) {
// ERROR: HTTP GET
})
.success(function(response) {
$scope.result = response.data;
// debug - they both alert the same thing
//alert(response.data.search_type);
//alert($scope.result.search_type);
currentIonicSlideBoxDelegate.enableSlide(true);
currentIonicSlideBoxDelegate.update();
})
.finally(function() {
//
});
} else {
// ALERT: criteria is not set
}
};
});
您的jsFiddler不工作,因此我无法测试它,但我认为它会工作。找到它!这是我的错误。同一控制器中有一个控制器
ng-controller="UserSearchCtrl"
抱歉,但我不确定我是否可以发布URL,并且我没有测试URL来代替..我还尝试使用$scope.$apply(function(){});无论是设置变量还是更新,都会失败。出于这个原因,我假设,不存在异步问题..您没有在webbrowser的控制台中得到错误吗?没有,没有。通过提醒,我可以得到结果。我可以把结果写在html的任何地方。我不能做的是更新幻灯片。我已经更新了帖子。如果在单击时调用该函数,它也可以工作。它是否已解决,或者是否需要对其进行处理?
engine.module.controller('UserSearchCtrl', function($scope, $rootScope, $http, $ionicSlideBoxDelegate, $timeout, $state, $stateParams, $db, $user) {
var currentIonicSlideBoxDelegate = $ionicSlideBoxDelegate;
currentIonicSlideBoxDelegate.enableSlide(false);
$scope.width = window.outerWidth;
// if I wrap the below ajax fn in a function, called on submit, it stops working
$scope.retrieveResults = function() {
var token = $rootScope.user.token;
if ($scope.criteria !== '') {
$http.get(engine.config.REMOTE_URL + '/search?' + 'token=' + token)
.error(function(err) {
// ERROR: HTTP GET
})
.success(function(response) {
$scope.result = response.data;
// debug - they both alert the same thing
//alert(response.data.search_type);
//alert($scope.result.search_type);
currentIonicSlideBoxDelegate.enableSlide(true);
currentIonicSlideBoxDelegate.update();
})
.finally(function() {
//
});
} else {
// ALERT: criteria is not set
}
};
});
ng-controller="UserSearchCtrl"