June 2014
Intermediate to advanced
696 pages
38h 52m
English
With the weather service and route defined on the Node.js server side, you can implement a controller that accesses the route to get weather data. Listing 29.10 implements weatherController in the AngularJS application Module object. The scope contains a list of cities and the location or city name used when getting weather data. Also, a locationIn value is defined to provide a model for a text input to add new city names.
The getWeather() function makes an $http GET request, passing the city parameter from $scope.location, and sets the $scope.weather value that will be bound to the view.
The addCity() function uses locationIn to add new cities to the cities array. If a city already exists, then it is ...
Read now
Unlock full access