The following code populates a select based on the tab you have selected. My question is how can i do this by loading the select options via api or just an external source?
2 Answers
Populating selects from an external api is no different. When the controller inits, have it run out and get the options (or better yet, resolve them before he controller is initialized) and bind that scope variable to the select. I.e.
In the controller:
module.controller...function(scope, service) {
scope.selectOptions = [];
service.get().then(function(response){
scope.selectOptions = response.data;
});
}
In the view:
<select ng-model="selectedDocument" ng-options="option.name for option in selectOptions"></select>
Comments
Check out AngularJS's documentation for the $http service
http://code.angularjs.org/1.0.8/docs/api/ng.$http.
With it, you can call an internal (or external) web service that can respond to your input (input being the selected tab id) with the appropriate JSON response.
In your JavaScript you can load these values upfront, or on-demand when clicking on the appropriate tab.
$httpservice in angular to get some JSON - is that you're referring to?