In this workshop we will try to create an AngularJS application that utilizes most aspects of the framework. This workshop creates everything from scratch, step by step, so the participants can understand and follow how to build an AngularJS application. It does not include building a production ready application (concatination, minification, less -> css) since it adds complexity.
Create an Hello World AngularJS application.
- Creating an index.html.
- Include angular.js from http://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.js.
- Bootstrap AngularJS by adding a HTML-element with the ng-app attribute.
- Give your Angular a name by setting the ng-app attribute value to the name of your application (should start with lower case). In the examples,
weatherApp
is used. - Create a new Javascript file called app.js which declares the module
weatherApp
. - Include
app.js
inindex.html
.
- Create a controller in controller/SearchTermController.js.
- Declare a $scope property.
- Update template to display the $scope property.
- Create a form with
ng-submit
. - Create input field in form that is bound to scope in controller.
- Give your controller a name.
- Add a error message that is shown if the field is empty.
- Create a service with a $resource with url: http://api.openweathermap.org/data/2.5/weather?q=London,uk.
- Call the service from your controller where the input from your form is sent as an argument to the service ( q=).
- Display weather response in the controller.
- Replace "main view" with a ng-view directive, add what was in the main view before into a separate template.
- Add routing for "#/" so the new template is show in the ng-view directive.
- Add a new route which should be used to display weekly weather with its own template.
- Update menu to link to your new route.
- Create a new resource with the url http://api.openweathermap.org/data/2.5/forecast/daily?q=London,uk.&cnt=7
- Display the weather for the next 7 days in the view.
- Create a directive so the weather icon does not perform a GET request before the interpolation is done. (One solution: Put the uninterpolated icon url in the directive. Do not set img.src before the model has the icon property set)
- Create a directive which use the directive in the above task, but also display other weather data. (Tip: Use transclude: true and </weather)
- Create a new route and template.
- Create a complex form with url and email inputs (dropdown? radio? checkbox?).
- Try not to display error messages until the user has tried to submit the form, possible?
- When switching between the routes "today" and "weekly", try to utilize the "resolve" functionality to only switch to new route when the target data is fetched from openweathermap (or display error in current route if data fetching fails).
- Show a loader when there are pending HTTP requests so the user get visual feedback.