This document provides an introduction to AngularJS. It explains that AngularJS is a JavaScript MVC framework and not just a library. It describes key Angular concepts like directives, controllers, services and dependency injection which make Angular apps modular and components easily testable. Testing is emphasized as equally important as writing code. The document also introduces tools like Karma and Protractor that are useful for automated testing of Angular apps in browsers.
34. A step back: Scopes
Scope ~ Model ~ Current state
35. A step back: Scopes
Scope ~ Model ~ Current state
Scopes are objects organized hierarchically,
aimed to mimic the DOM structure
36. A step back: Scopes
Each module instantiate a rootScope object
Scope ~ Model ~ Current state
Scopes are objects organized hierarchically,
aimed to mimic the DOM structure
50. Misko Hevery
“Agile Coach at Google where he is
responsible for coaching Googlers to
maintain the high level of automated
testing culture”
- misko.hevery.com/about/
56. DI as Pattern
function Car() {
var wheel = new Wheel();
var engine = Engine.getInstance();
var door = app.get(‘Door’);
!
this.move = function() {
engine.on();
wheel.rotate();
door.open();
}
}
57. DI as Pattern
function Car() {
var wheel = new Wheel();
var engine = Engine.getInstance();
var door = app.get(‘Door’);
!
this.move = function() {
engine.on();
wheel.rotate();
door.open();
}
}
58. DI as Pattern
function Car(wheel, engine, door) {
this.move = function() {
engine.on();
wheel.rotate();
door.open();
}
}
59. The problem
function main() {
var fuel = new Fuel();
var electricity = new Electricity();
var engine = new Engine(fuel);
var door = new Door(Electricity);
var wheel = new Wheel();
var car = new Car(wheel, engine, door);
car.move();
}
60. The problem
function main() {
var fuel = new Fuel();
var electricity = new Electricity();
var engine = new Engine(fuel);
var door = new Door(Electricity);
var wheel = new Wheel();
var car = new Car(wheel, engine, door);
car.move();
}
61. The problem
function main() {
var fuel = new Fuel();
var electricity = new Electricity();
var engine = new Engine(fuel);
var door = new Door(Electricity);
var wheel = new Wheel();
var car = new Car(wheel, engine, door);
car.move();
}
62. The problem
function main() {
var fuel = new Fuel();
var electricity = new Electricity();
var engine = new Engine(fuel);
var door = new Door(Electricity);
var wheel = new Wheel();
var car = new Car(wheel, engine, door);
car.move();
}
63. DI as framework
function main() {
var injector = new Injector(….);
var car = injector.get(Car);
car.move();
}
64. DI as framework
function main() {
var injector = new Injector(….);
var car = injector.get(Car);
car.move();
}
Car.$inject = [‘wheel’, ‘engine’, ‘door’];
function Car(wheel, engine, door) {
this.move = function() {
…
}
}
65. DI as framework
function main() {
var injector = new Injector(….);
var car = injector.get(Car);
car.move();
}
Car.$inject = [‘wheel’, ‘engine’, ‘door’];
function Car(wheel, engine, door) {
this.move = function() {
…
}
}
76. Directive Test
it(‘Check launchpad was installed', function() {
var element = $compile(“<rocket-launch-pad></
rocket-launch-pad>”)($rootScope);
!
expect(element.html()).toContain("Rocket here");
});