Last active
November 8, 2018 07:35
-
-
Save jquery404/95bb27d88c238887e2af17ca720f561e to your computer and use it in GitHub Desktop.
Async HTTP call AngularJS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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