Question: **Requirement is to display the selected option inside controller and populate other select on the basis of currently selected option.**

Below the HTML code snippet:

```
<html ng-app="myApp">
....
 <section ng-controller="myCtrl">
  <select ng-model="selectedName" ng-options="x for x in category">
 </select>
  <select ng-model="selectedSubName" ng-options="x for x in subcategory">
 </select>
 </section>
....
</html>

```

The controller used:

```
<script>
var app = angular.module('myApp', []);
 app.controller('myCtrl', function($scope) {

 $scope.category = ["Design", "UI", "Web Stack", "Unit Testing"];
 //Use Conditional Statements to populate options for the other <select> 
  i.e, subcategory

 $scope.subcategory = ["HTML", "CSS", "JS", "Java"];
});
</script>

```

Answer: 
[Async](https://caolan.github.io/async/) provides control flow methods allowing to do so.

Using [async.each](https://caolan.github.io/async/docs.html#each):

```
async.each(openFiles, function(file, callback) {

    // Perform operation on file here.
    console.log('Processing file ' + file);

    if( file.length > 32 ) {
      console.log('This file name is too long');
      callback('File name too long');
    } else {
      // Do work to process file here
      console.log('File processed');
      callback();
    }
}, function(err) {
    // if any of the file processing produced an error, err would equal that error
    if( err ) {
      // One of the iterations produced an error.
      // All processing will now stop.
      console.log('A file failed to process');
    } else {
      console.log('All files have been processed successfully');
    }
});

```
Since you are using promise, you can do something like this

```
exports.listTopSongs = function(query) {
    return Promise.resolve(true).then(function(){
        var str = query.split(",");
        var promises = str.map(function(s){
            return sampleFn(str[i], 'sample');
        });
        return Promise.all(promises);
    }).then(function(results){
       //whatever you want to do with the result
    });
};

```

For this to work you have to change your **sampleFn** to not to depend on external resolve and reject functions. I don't see a reason using external resolve and reject. why just not use **Promise.Resolve, Promise.Reject**;