
var app = angular.module('simpleapp', ['ng', 'ngRoute']);

app.controller(
    'simpleController',
    function ($scope, $location, $http) {
        $scope.currentUrl = $location.absUrl();
    }
);

app.config(
    function ($routeProvider, $locationProvider) {
        $locationProvider.html5Mode(true);
        $routeProvider.when(
            '/weather',
            {
                template: '<h2>Weather for {{weather.name}}</h2><pre>{{weather | json}}</pre>',
                resolve: {
                    weatherData: function ($http) {
                        return $http.get(
                            'http://api.openweathermap.org/data/2.5/weather?q=San%20Francisco,%20CA,%20US'
                        ).then(function (resp) { return resp.data; });
                    }
                },
                controller: function (weatherData, $scope) {
                    $scope.weather = weatherData;
                }
            }
        );
        $routeProvider.otherwise(
            {
                template: '<a href="/weather">Weather</a>'
            }
        );
    }
);


var app = angular.module('simpleapp', ['ng', 'ngRoute']);

app.controller(
    'simpleController',
    function ($scope, $location, $http) {
        $scope.currentUrl = $location.absUrl();
    }
);

app.controller(
    'weatherController',
    function (weatherData, $scope) {
        $scope.weather = weatherData;
    }
);

app.config(
    function ($routeProvider, $locationProvider) {
        $locationProvider.html5Mode(true);
        $routeProvider.when(
            '/weather',
            {
                template: '<h2>Weather for {{weather.name}}</h2><pre>{{weather | json}}</pre>',
                resolve: {
                    weatherData: function ($http) {
                        return $http.get(
                            'http://api.openweathermap.org/data/2.5/weather?q=San%20Francisco,%20CA,%20US'
                        ).then(function (resp) { return resp.data; });
                    }
                },
                controller: 'weatherController'
            }
        );
        $routeProvider.otherwise(
            {
                template: '<a href="/weather">Weather</a>'
            }
        );
    }
);

Make the weather page use a named controller.
Make the weather page use a named controller.

We have to use named controllers rather than inline controllers because
we want to be able to indicate to the client which controller to use to
render the page. We can send the client a string to look up, but we can't
reliably serialize the controller function and transmit it.
