Skip to content

Instantly share code, notes, and snippets.

@jquery404
Last active November 8, 2018 07:35
Show Gist options
  • Save jquery404/95bb27d88c238887e2af17ca720f561e to your computer and use it in GitHub Desktop.
Save jquery404/95bb27d88c238887e2af17ca720f561e to your computer and use it in GitHub Desktop.
Async HTTP call AngularJS
<div class="col-md-6 col-sm-6 col-xs-12">
<select
ng-change="changeCluster(1)"
ng-options="s.cluster_id as s.cluster_title for s in parentLevel"
ng-model="currentCluster.co_sub_cluster">
</select>
</div>
<div class="col-md-6 col-sm-6 col-xs-12">
<div class="clearfix">
<select
ng-change="changeCluster(2)"
ng-options="s.cluster_id as s.cluster_title for s in childLevel"
ng-model="currentCluster.sub_cluster">
</select>
</div>
</div>
<script>
app.controller('clusterCrtl', function ($scope, $http, $timeout, $q) {
$scope.EditCluster = function(){
this.getCluster(0).then(function(response){
$scope.parentLevel = response;
});
this.getCluster(coSubClusterId).then(function(response){
$scope.childLevel = response;
});
this.getCluster(subClusterId).then(function(response){
$scope.grandChildLevel = response;
});
};
$scope.getCluster = function(id){
var deferred = $q.defer();
$http.get('<?php echo URL_root; ?>ws/ws_cluster.php', {
params:{
task: 10,
parent: id,
}
}).success(function (response) {
var data = response.record;
deferred.resolve(data);
});
return deferred.promise;
};
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment