- structural framework (made by Google)
- extend HTML syntax (template language)
- implementation of MVC design pattern (MVVM)
- allow us to separate out components (pieces) of an app -> controllers, services, directives, constants, filters, templates
- framework (angular) handles the initialization and interaction of these pieces
- Modules
- Library (jQuery, underscore, lodash,... ) vs Framework (Angular, Backbone,...)
- clean separation between: view (UI), controller (intermediary) and model (data)
- separate data management and presentation.
- The view is a projection of the model at all times.
- VM in AngularJS -> $scope object
An angular application consists of
- controllers: interlayer between model (service) and view (template)
- templates: view
- directives: UI components or custom tag attributes
- services: retrieve data from servers (dependency injection to controllers)
project root/
index.html // entry point for our application
javascript/
app.js // defines our application and configuration
controller.js // our controllers
directive.js // our directives
service.js // our services
templates/
// our application views or html files
css/
// our css files
vendor/
// any external libraries we wish to use e.g. bootstrap
// angular, jquery etc
- Adding
angular.js
and check the magic (two way binding) ofng-model
https://github.com/juanmaguitar/angular-demo-app/tree/step-1
An Angular application is made up of modules (Application Module, Controller Module, Service Module, Directive Module)
- Add application module in
app.js
and add proper references inindex.html
https://github.com/juanmaguitar/angular-demo-app/tree/step-2
Add controller module in controller.js
, add some controllers in it and add proper references in index.html
https://github.com/juanmaguitar/angular-demo-app/tree/step-3
- the $scope object is the ViewModel (is shared by the view and the controller)
- every controller has its own $scope
Add some properties to the controllers in controller.js
and show them in index.html
https://github.com/juanmaguitar/angular-demo-app/tree/step-4
ng-controller
sets a controller for a piece of html (view)ng-model
sets a two-way-binding data between the view and the controller
http://jsfiddle.net/lillylangtree/jja3fjt6/1/
Adding methods to the $scope
https://github.com/juanmaguitar/angular-demo-app/tree/step-5
ng-repeat
sets a controller for a piece of html (view)
https://github.com/juanmaguitar/angular-demo-app/tree/step-6
- will hide or show those elements that fullfill some condition
https://github.com/juanmaguitar/angular-demo-app/tree/step-7
- will execute some function defined in the scope when clicking the element
https://github.com/juanmaguitar/angular-demo-app/tree/step-8
https://github.com/juanmaguitar/angular-demo-app/tree/step-9
- filters select a subset of elements displayed w/
ng-repeat
- the 'alias' object (subject in
ng-repeat="subject in student.subjects
) gets passed to the filter function by default.
https://github.com/juanmaguitar/angular-demo-app/tree/step-10
- we can order the results of the ng-repeat iteration by adding an
orderBy
filter component
https://github.com/juanmaguitar/angular-demo-app/tree/step-11
More Filter components: https://docs.angularjs.org/api/ng/filter
## Examples
VERY BASIC Angular app (routes, controllers, views...)
Repository: https://github.com/xxMShipmanxx/AngularJS_template
BASIC Angular app done w/ Google design (Materialize) and backend connection (Firebase) to store data
Repository: https://github.com/thompsonemerson/simple-app-angular
Demo: http://thompsonemerson.github.io/simple-app-angular/#/
JSFiddle example that shows that the order of executions in angular is:
app.config()
app.run()
directive
's compile functions (if they are found in the dom)app.controller()
directive
's link functions (again, if found)
Explanation: http://stackoverflow.com/a/20664122/1526811
Example: http://jsfiddle.net/ysq3m/
Very well structured app but a more complexed one
Calls to API in services, CRUD app
Bootstrap, unit tests, E2E tests
Repository: https://github.com/DBProductions/angularjs-starter-app
Step by Step build of an app
git checkout step-?
Tutorial: https://docs.angularjs.org/tutorial
Repository: https://github.com/juanmaguitar/angular-phonecat
## Docs
- https://docs.google.com/document/d/1jw8f5Nc75eYotZAiPdKIX-wldaDVKJLcuOU6EyV4SDE/
- https://docs.angularjs.org/tutorial
## Extra info