The controller package

Our controller interface is really straightforward. It exposes a set of methods that can be used in the HTML template to trigger operations:

  1.  loadCountries will be invoked when the application starts. This method will retrieve the list of countries from the World Bank API using the population service. That list will then be displayed onscreen by the view layer.
  1.  loadYears will also be called when the application starts. It will generate a list of years that the user can choose via select boxes. These will be used to define the range of data to fetch in order to create the charts (for example, 2000-2010).
  2.  renderChart will gather the information needed to create a new chart and will then ask the view to render it onscreen.
loadYears and loadCountries are both asynchronous. For the list of countries, it is obviously because we need to make an API call. In the case of loadYears, we'll see later why that is the case.

Our controller implementation will have a view at its disposal, as well as an instance of the population service to fetch the data.