SlideShare ist ein Scribd-Unternehmen logo
1 von 81
Downloaden Sie, um offline zu lesen
Beginning AngularJS
13 & 14 June 2015, Cowork South Bay
Troy Miles
Resources
http://www.slideshare.net/rockncoder/beginning-
angularjs
https://github.com/Rockncoder/ng-contacts
https://github.com/Rockncoder/todo
Troy Miles
Over 35 years of programming experience
Blog: http://therockncoder.blogspot.com/
Twitter: @therockncoder
Email: rockncoder@gmail.com
GitHub: https://github.com/Rockncoder
Agenda Day One
Introduction
Tools
Using Yeoman
To Do App
Testing
Animation
Services/Modules
Controller As
Filters
Agenda Day Two
Deployment
Providers
Contacts App
$http & Promises
$resource
Testing ajax calls
Firebase
Custom Directives
Wrap-up
Lab #1 - Setup Check
In the labs directory
Launch the hello.html web page
You should see a greeting displayed
Lab Solution
Browser expect web applications to be delivered via a
web server
While most browser will allow a web page to run from a
file, most won’t allow it to access other files
If your machine is setup correctly, you will see a
greeting
Lab #2 - jQuery Binding
From the labs folder open the binding.html file
Write JavaScript to transfer the text contents of the input tag
with the id of firstName, to the span with the id of showName
The code should be interactive and update as the user types
Write you code in the empty script tag near the end of the
page
jQuery is already included on the page
jQuery Example
<!DOCTYPE html>

<html>

<head lang="en">

<meta charset="UTF-8">

<title>Binding</title>

<script src="../lib/jquery-1.10.2.min.js"></script>

</head>

<body>

<label for="firstName">Enter Your Name:</label>

<input type="text" id="firstName"/>

<h2>Display Your Name Below</h2>

<label for="showName">Show Your Name:</label>

<span id="showName"></span>



<script>

$( document ).ready( function(){

$('#firstName').on("keyup", function(){

$('#showName').text(this.value);

});

});

</script>

</body>

</html>
What’s Wrong with jQuery
jQuery is a very popular library
It is used on 50% of all web sites
It is a library not a framework
It is difficult code to test
It can lead to the creation of spaghetti code
AngularJS Example
<!DOCTYPE html>

<html ng-app>

<head lang="en">

<meta charset="UTF-8">

<title>NG-Binding</title>

<script src="../lib/angular.min.js"></script>

</head>

<body>

<label>Enter Your Name:</label>

<input type="text" ng-model="firstName"/>

<h2>Display Your Name Below</h2>

<label>Show Your Name:</label>

<span>{{firstName}}</span>



<script>

</script>

</body>

</html>
Strict Mode
Strict mode allows you to opt in to a more restrictive
version of JavaScript
Things usually permitted in JS become errors
Can be applied to an entire script or individual
functions
Strict mode is a JavaScript best practice
Invoking Strict Mode
Before any other statements place the following
statement
"use strict"; or 'use strict’;
Works on both the script and function level
Be careful of mixing strict and non-strict mode files
Other JavaScript MVC
Frameworks
Backbone.js
Knockout
EmberJS
Other frameworks & ToDoMVC
Backbone.js
Created by Jeremy Ashkenas
in 2010
19 kb production version
(minimized, not gzipped)
One dependency -
Underscore.js, optional jQuery
Three core concepts: models,
collections, & views
Uses lots of custom events
Knockout
Created by Steve Sanderson in
2010
47 kb production version
(minimized, not gzipped)
Uses MVVM pattern
Two way data-binding
No dependencies
Supports all mainstream
browsers
Ember
Created by Yehuda Katz and
Tom Dale in 2011
Convention over configuration
Ember Data, a separate
package, handles RESTful data
Handlebars.js, a separate
package, handles templates
337 kb production version
(minimized, not gzipped)
AngularJS
Created by Miško Hevery and
Adam Abrons in 2009
JavaScript MVC
106 kb production version
(minimized, not gzipped)
Declarative programming for
UI
Imperative programming for
business logic
AngularJS Key Features
Two Way Data-binding
Model View Controller
Dependency Injection
Deep Linking
HTML Templates
Directives
Testability
Two Way Data-binding
In AngularJS, binding is built into the framework
Replaces text content of HTML element with the value
of the expression
{{ expression }}
<ANY ng-bind=“expression”>…</ANY>
<ANY class=“ng-bind: expression;”>…</ANY>
Model View Controller
Uses MVC or MVVM or MV* depends on who you ask
The goal is clear separation of concerns
The model is only concerned with data
The view presents the data to the user
The controller applies the business logic
Dependency Injection
A software design pattern that implements inversion of
control and allows a program design to follow the
dependency inversion principle
Allows a dependency to be passed to an object
Allows code to clearly state dependencies
Leads to code which is easier to debug and test
Makes it possible to minimize apps without breaking them
Deep Linking
One feature that web sites have over desktop apps are
bookmarks
Deep linking allows AngularJS to restore state based
on a URL
Application can use hyperlinks to navigate users
around
HTML Templates
There are a lot of templating libraries
AngularJS instead uses HTML for its templates
AngularJS templates can pass HTML validators
Designers will feel at home
Easy to learn
Directives
Possibly the best thing in AngularJS
Directives extend the capabilities of HTML
Merge the declarative nature of HTML to the imperative
nature of JavaScript
Testability
AngularJS was engineered with testing in mind
It supports both unit and integration tests
For unit tests it works well with Jasmine
Karma is the test runner
npm
Included with Node.js
Installs many open source projects
https://www.npmjs.com/
Yeoman
Kickstarts a new project
Adheres to best practices
Uses Generators
http://yeoman.io/
Bower
Package manager for web applications
Keeps track of your libraries like jQuery, Bootstrap, etc
Dependencies kept in bower.json file
http://bower.io/
Grunt
JavaScript Task Runner
Does mundane work for you
Hundreds of plugins available
http://gruntjs.com/
AngularJS Directives
ng-app
ng-controller
ng-model
ng-bind
ng-repeat
ng-if
ng-switch
ng-include
ng-view
ng-src / ng-href
ng-bind vs ng-model
ng-bind is one way data binding, aka output
ng-bind renders a property on scope
ng-bind has a shortcut {{}}
ng-bind is preferred over shortcut
ng-model is for two-way data binding
ng-model is intended for form elements
<input ng-model='userName' />
Name Mangling
There are basic incompatibilities between names used in
HTML and those in JavaScript
HTML permits dashes and colons, JavaScript does not
To convert to JavaScript
delete any initial x-, data-
First letters after are capitalized
delete dashes, underscores, and colons
Name Mangling
So all of the following attributes equal timePicker:
data-time-picker
x:time-picker
time_picker
Lab - Greet-o-matic
Open the greet-o-magic.html file
Make the page functional
The user should be able to enter their name in either
input tag and have it reflect in the other and in the span
tag
You shouldn’t need to write any JavaScript
Two Way Data-binding
<!DOCTYPE html>

<html ng-app>

<head lang="en">

<meta charset="UTF-8">

<title>Greet-o-matic</title>

<link rel="stylesheet" href="../css/bootstrap.css"/>

<script type="text/javascript" src="../libs/angular.js"></script>

</head>

<body>

<div class="container" >

<h1>Greet-o-matic</h1>

<div class="col-lg-6">

<input type="text" ng-model="userName" placeholder="Enter name here"/>

</div>

<div class="col-lg-6">

<input type="text" ng-model="userName" placeholder="or over here"/>

</div>

<hr/>

<p>Hello <span>{{userName}}</span>,<br/>Have a nice day!</p>

</div>

</body>

</html>
$scope
An object which refers to the application model
The glue between the controller and the view
The execution context for expressions
Provides APIs
$watch - observes model
$apply - propagates model changes to AngularJS
Code Along - Todo App
A Todo app is the hello world app of JavaScript MVC
frameworks
It shows how to create an app which creates, reads,
updates, and deletes data (CRUD)
Let’s build one together
Code Along - Todo App Steps
create shell page with
angular link
create script tag for JS
add ng-app with module
name ‘ToDo’
create angular module
create todo controller
create todos array
create add method
create delete method
create complete method
Code Along - Todo App Steps
add markup
add functionality to methods
clear text box after added
Jasmine
Latest version 2.2, but we will be using 2.0.2
The default unit tester for AngularJS
Others will also work
Behavior Driven Development (BDD) approach
Describe - test suite
Describe is a global jasmine function
Two params
string - name of the test suite
function - implementation of the suite
Can be nested
it - specs
it is a global jasmine function
Looks like describe
A spec contains one or more expectations
If all expectations true, it is a passing spec
If any expectation fails, it is a failing spec
Expectations
Expect function
One param
The actual
Chained to a Matcher function
Matchers
Take the output of the expect function and compare it
to something
Implement a boolean compare between actual value
and expected
Reports to Jasmine if the expectation is true or false
Any matcher can be negated with a not before it
Some matchers
toBe - compares using ===
toEqual - works for literal variables and objects
toMatch - for regular expressions
toBeDefined - compares against 'undefined'
toBeUndefined - also compares against ‘undefined'
Some matchers (CONTINUE)
toBeNull - compares against null
toBeTruthy - truthy boolean casting
toBeFalsy - falsy boolean casting
toContain - finds an item in array
Some matchers (CONTINUE)
toBeLessThan
toBeGreaterThan
toBeCloseTo - precision math comparison
toThrow - should throw an exception
beforeEach / afterEach
Are setup and teardown functions
called before and after each spec it
this
beforeEach, it, and afterEach share the same this
it is cleared before call spec call
any beforeEach not included in a describe block is executed before any
Jasmine test
can use this to add custom matchers
Disabling suites and specs
prepend an 'x' before describe or it
specs inside a disabled suite are not ran
Unit Testing 3As
Arrange - Set up object to be tested
Act - Act on the object
Assert - Test the state of the object
TDD vs BDD
Dev writes test
Run tests - fail
Implement tests in code
Run tests - pass
Refactor code
Dev writes behavior and
specs
Run specs - fail
Implement specs in code
Run specs - pass
Refactor code
Views
template - String contain HTML to display
templateUrl - Relative URL of file holding HTML or id of
DOM element holding HTML
Inline View Template
The id name in the script tag matches…
templateUrl value of the route
template stored in index.html or other HTML file
54
<script id="contact.html" type="text/ng-template">

<h2>Contact</h2>

<hr/>

<p>For more information email rockncoder@gmail.com</p>

<hr/>

</script>
Providers
What are providers?
Types of providers
Services
Factories
Providers
What are providers?
Objects that are instantiated and wired together
automatically by the injector service
The injector creates two kinds of objects:
services - defined by the developer
specialized objects - Angular framework pieces,
controllers, directives, filters, or animations
Types of providers
Constants
Value
Decorator
Provider
Service
Factory
Services
Substitutable objects that are wired together using DI
Used to organize and share code across app
Only instantiated when an app component depends on
it
Singletons
Built-in services always start with “$”
Factories
Introduction to shared components
Dependency injection deep dive
Building custom factories & services
Persisting data to a Web API service
Lab - ng-contacts
We are going to super size the Todo app into a
contacts
We will Firebase as our backend
We can develop locally and then deploy
Firebase
A powerful API to store and sync data in realtime
Offer free developer accounts
Both backend data and hosting
No real arrays (limitation due to contention problem)
Used by AngularJS.org site
https://www.firebase.com/
Firebase Data Limits
A node's key max length 768
A node can't be nested deeper than 32 levels
Any unicode character except .$[]/ plus the ASCII
control keys of 0-31 and 127
Firebase Sizes
One child value - 100 mb UTF-8 encoded
SDK write value max - 16 mb UTF-8
REST write value max - 100 mb UTF-8
Nodes in a read operation 100 million
Firebase Writing Data
set()
Saves data to the specified Firebase reference
Any existing data at the path is overwritten
update()
push()
transaction
Firebase Installation
Add script tag for firebase
Add script tag for AngularFire
Add firebase.json file
Create a firebase reference object
Filters
Understanding Filters
A tour of built-in filters
Building custom Filters
Lab
Understanding Filters
Used to format data displayed to user
Strictly front-end, doesn’t change model data
Accessible using declarative or imperative syntax
{{ expression [| filter_name[:parameter_value] ... ] }}
$scope.originalText = 'hello';

$scope.filteredText = $filter('uppercase')
($scope.originalText);
A tour of built-in filters
currency
date
json
lowercase
uppercase
number
filter
limitTo
orderBy
Building custom filters
tempApp.filter('minimum', [function () {

return function (arrTemp, minimum) {

var filteredArray = [];

var min = minimum ? minimum : 15;

angular.forEach(arrTemp, function (value, key) {

if (value.temp >= min) filteredArray.push(value);

});

return filteredArray;

};

}]);

Lab - Using Filters
Let’s add a search filter to our contacts app
Directives
Introduction to Directives
jQuery integration
Using a jQuery UI Widget
Directives
Markers on a DOM element that attach a behavior to it
Can be an attribute, element name, comment, or CSS
The HTML compiler traverses the DOM at bootstrap
and matches directives to DOM elements
Directives Names
<div timePicker></div>
<div time-picker></div>
<div time:picker></div>
<div time_picker></div>
<div x-time-picker></div>
<div data-time-picker></div>
Directive Location
Tag name: <timePicker></timePicker>
Attribute: <div data-rnc-time-picker></
div>
Class: <div class=“time-picker;”></div>
Comment: <!— directive:time-picker —>
Built-in Directives
ng-app
ng-bind
ng-controller
ng-href
ng-readonly
ng-repeat
ng-src
ng-submit
ng-transclude
ng-view
jQuery Integration
AngularJS includes a mini version of jQuery called
jqLite
But it is perfectly compatible with the jQuery
jQuery must be loaded before Angular or it won’t see it
Using a jQuery Widget
app.directive('timePicker', function () {

var today = new Date(new Date().toDateString());

return {

require: '?ngModel',

link: function ($scope, $element, $attrs, ngModel) {

var initialized = false;



ngModel = ngModel || {

"$setViewValue": angular.noop

};



// where is the missing time value?

setTimeout(function () {

initialized = $element.timepicker()

.on('changeTime', function (ev, ui) {

var sec = $element.timepicker('getSecondsFromMidnight');

ngModel.$setViewValue(sec * 1000);

console.log("sec = " + sec);

});

});



ngModel.$render = function (val) {

if (!initialized) {

//If $render gets called before our timepicker plugin is ready, just return

return;

}

$element.timepicker('setTime', new Date(today.getTime() + val));

}

}

}

});
Lab - jQuery UI Widget
Let’s add a jQuery UI calendar widget to our contact
app
We will essentially wrap it to make it “angularized”
Summary
Modern Web Apps
Compared AngularJS’ way to jQuery’s
AngularJS’ Core Concepts
Controllers
Todo App
Contacts App
Summary
Firebase
Custom Directives
Filters
Integrating jQuery Widgets with AngularJS
Troy Miles
Over 30 years of programming experience
Blog: http://therockncoder.blogspot.com/
Twitter: @therockncoder
Email: rockncoder@gmail.com
GitHub: https://github.com/Rockncoder

Weitere ähnliche Inhalte

Was ist angesagt?

Usability in the GeoWeb
Usability in the GeoWebUsability in the GeoWeb
Usability in the GeoWebDave Bouwman
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.jsMek Srunyu Stittri
 
Demystifying Keyword Driven Using Watir
Demystifying Keyword Driven Using WatirDemystifying Keyword Driven Using Watir
Demystifying Keyword Driven Using WatirHirday Lamba
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptKaty Slemon
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfKaty Slemon
 
From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.David Aguilera
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and BeyondWebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyondmguillem
 
Angular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHEREAngular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHERENadav Mary
 
3 Simple Steps to follow to Create React JS Components
3 Simple Steps to follow to Create React JS Components3 Simple Steps to follow to Create React JS Components
3 Simple Steps to follow to Create React JS ComponentsSurendra kumar
 
BDD with JBehave and Selenium
BDD with JBehave and SeleniumBDD with JBehave and Selenium
BDD with JBehave and SeleniumNikolay Vasilev
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersOswald Campesato
 
Bdd with Cucumber and Mocha
Bdd with Cucumber and MochaBdd with Cucumber and Mocha
Bdd with Cucumber and MochaAtish Narlawar
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JSMichael Haberman
 
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...Alan Richardson
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravelDerek Binkley
 
Selenium - The page object pattern
Selenium - The page object patternSelenium - The page object pattern
Selenium - The page object patternMichael Palotas
 
Out of box page object design pattern, java
Out of box page object design pattern, javaOut of box page object design pattern, java
Out of box page object design pattern, javaCOMAQA.BY
 

Was ist angesagt? (20)

Usability in the GeoWeb
Usability in the GeoWebUsability in the GeoWeb
Usability in the GeoWeb
 
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 -  Fullstack end-to-end Test Automation with node.jsForwardJS 2017 -  Fullstack end-to-end Test Automation with node.js
ForwardJS 2017 - Fullstack end-to-end Test Automation with node.js
 
Demystifying Keyword Driven Using Watir
Demystifying Keyword Driven Using WatirDemystifying Keyword Driven Using Watir
Demystifying Keyword Driven Using Watir
 
How to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScriptHow to Build ToDo App with Vue 3 + TypeScript
How to Build ToDo App with Vue 3 + TypeScript
 
Flutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdfFlutter State Management Using GetX.pdf
Flutter State Management Using GetX.pdf
 
Asp net-mvc-3 tier
Asp net-mvc-3 tierAsp net-mvc-3 tier
Asp net-mvc-3 tier
 
From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.From Good to Great: Functional and Acceptance Testing in WordPress.
From Good to Great: Functional and Acceptance Testing in WordPress.
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and BeyondWebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
 
Angular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHEREAngular elements - embed your angular components EVERYWHERE
Angular elements - embed your angular components EVERYWHERE
 
Integration testing - A&BP CC
Integration testing - A&BP CCIntegration testing - A&BP CC
Integration testing - A&BP CC
 
3 Simple Steps to follow to Create React JS Components
3 Simple Steps to follow to Create React JS Components3 Simple Steps to follow to Create React JS Components
3 Simple Steps to follow to Create React JS Components
 
BDD with JBehave and Selenium
BDD with JBehave and SeleniumBDD with JBehave and Selenium
BDD with JBehave and Selenium
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
 
Bdd with Cucumber and Mocha
Bdd with Cucumber and MochaBdd with Cucumber and Mocha
Bdd with Cucumber and Mocha
 
Unit-testing and E2E testing in JS
Unit-testing and E2E testing in JSUnit-testing and E2E testing in JS
Unit-testing and E2E testing in JS
 
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
Hands on Exploration of Page Objects and Abstraction Layers with Selenium Web...
 
Testing with laravel
Testing with laravelTesting with laravel
Testing with laravel
 
Selenium - The page object pattern
Selenium - The page object patternSelenium - The page object pattern
Selenium - The page object pattern
 
Behavior Driven Development Testing (BDD)
Behavior Driven Development Testing (BDD)Behavior Driven Development Testing (BDD)
Behavior Driven Development Testing (BDD)
 
Out of box page object design pattern, java
Out of box page object design pattern, javaOut of box page object design pattern, java
Out of box page object design pattern, java
 

Ähnlich wie AngularJS Beginner Workshop

Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day trainingTroy Miles
 
Angular training - Day 3 - custom directives, $http, $resource, setup with ye...
Angular training - Day 3 - custom directives, $http, $resource, setup with ye...Angular training - Day 3 - custom directives, $http, $resource, setup with ye...
Angular training - Day 3 - custom directives, $http, $resource, setup with ye...murtazahaveliwala
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS OrisysIndia
 
SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011David O'Dowd
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJSPeter Drinnan
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseEPAM Systems
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Appschrisb206 chrisb206
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullySpringPeople
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083Divyam Pateriya
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)Chiew Carol
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSmurtazahaveliwala
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015Pushkar Chivate
 

Ähnlich wie AngularJS Beginner Workshop (20)

Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day training
 
Angular training - Day 3 - custom directives, $http, $resource, setup with ye...
Angular training - Day 3 - custom directives, $http, $resource, setup with ye...Angular training - Day 3 - custom directives, $http, $resource, setup with ye...
Angular training - Day 3 - custom directives, $http, $resource, setup with ye...
 
The Basics Angular JS
The Basics Angular JS The Basics Angular JS
The Basics Angular JS
 
Codeception
CodeceptionCodeception
Codeception
 
Introduction to Angular Js
Introduction to Angular JsIntroduction to Angular Js
Introduction to Angular Js
 
SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011SoftTest Ireland: Model Based Testing - January 27th 2011
SoftTest Ireland: Model Based Testing - January 27th 2011
 
Testing in AngularJS
Testing in AngularJSTesting in AngularJS
Testing in AngularJS
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
Html JavaScript and CSS
Html JavaScript and CSSHtml JavaScript and CSS
Html JavaScript and CSS
 
Jsp and jstl
Jsp and jstlJsp and jstl
Jsp and jstl
 
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-AppsSelenium-Browser-Based-Automated-Testing-for-Grails-Apps
Selenium-Browser-Based-Automated-Testing-for-Grails-Apps
 
Grails Advanced
Grails Advanced Grails Advanced
Grails Advanced
 
Mastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium SuccessfullyMastering Test Automation: How To Use Selenium Successfully
Mastering Test Automation: How To Use Selenium Successfully
 
Angular js
Angular jsAngular js
Angular js
 
Server side programming bt0083
Server side programming bt0083Server side programming bt0083
Server side programming bt0083
 
React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)React Native +Redux + ES6 (Updated)
React Native +Redux + ES6 (Updated)
 
Qa process
Qa processQa process
Qa process
 
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJSAngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
AngularJS training - Day 1 - Basics: Why, What and basic features of AngularJS
 
JavaScript Unit Testing
JavaScript Unit TestingJavaScript Unit Testing
JavaScript Unit Testing
 
SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015SharePoint Saturday Atlanta 2015
SharePoint Saturday Atlanta 2015
 

Mehr von Troy Miles

Fast C++ Web Servers
Fast C++ Web ServersFast C++ Web Servers
Fast C++ Web ServersTroy Miles
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot CampTroy Miles
 
AWS Lambda Function with Kotlin
AWS Lambda Function with KotlinAWS Lambda Function with Kotlin
AWS Lambda Function with KotlinTroy Miles
 
React Native One Day
React Native One DayReact Native One Day
React Native One DayTroy Miles
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
Intro to React
Intro to ReactIntro to React
Intro to ReactTroy Miles
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application TestingTroy Miles
 
What is Angular version 4?
What is Angular version 4?What is Angular version 4?
What is Angular version 4?Troy Miles
 
Angular Weekend
Angular WeekendAngular Weekend
Angular WeekendTroy Miles
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN StackTroy Miles
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScriptTroy Miles
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in ClojureTroy Miles
 
MEAN Stack Warm-up
MEAN Stack Warm-upMEAN Stack Warm-up
MEAN Stack Warm-upTroy Miles
 
The JavaScript You Wished You Knew
The JavaScript You Wished You KnewThe JavaScript You Wished You Knew
The JavaScript You Wished You KnewTroy Miles
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Troy Miles
 
Build a Game in 60 minutes
Build a Game in 60 minutesBuild a Game in 60 minutes
Build a Game in 60 minutesTroy Miles
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEANTroy Miles
 
A Quick Intro to ReactiveX
A Quick Intro to ReactiveXA Quick Intro to ReactiveX
A Quick Intro to ReactiveXTroy Miles
 

Mehr von Troy Miles (20)

Fast C++ Web Servers
Fast C++ Web ServersFast C++ Web Servers
Fast C++ Web Servers
 
Node Boot Camp
Node Boot CampNode Boot Camp
Node Boot Camp
 
AWS Lambda Function with Kotlin
AWS Lambda Function with KotlinAWS Lambda Function with Kotlin
AWS Lambda Function with Kotlin
 
React Native One Day
React Native One DayReact Native One Day
React Native One Day
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
Angular Application Testing
Angular Application TestingAngular Application Testing
Angular Application Testing
 
ReactJS.NET
ReactJS.NETReactJS.NET
ReactJS.NET
 
What is Angular version 4?
What is Angular version 4?What is Angular version 4?
What is Angular version 4?
 
Angular Weekend
Angular WeekendAngular Weekend
Angular Weekend
 
From MEAN to the MERN Stack
From MEAN to the MERN StackFrom MEAN to the MERN Stack
From MEAN to the MERN Stack
 
Functional Programming in JavaScript
Functional Programming in JavaScriptFunctional Programming in JavaScript
Functional Programming in JavaScript
 
Functional Programming in Clojure
Functional Programming in ClojureFunctional Programming in Clojure
Functional Programming in Clojure
 
MEAN Stack Warm-up
MEAN Stack Warm-upMEAN Stack Warm-up
MEAN Stack Warm-up
 
The JavaScript You Wished You Knew
The JavaScript You Wished You KnewThe JavaScript You Wished You Knew
The JavaScript You Wished You Knew
 
Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1Game Design and Development Workshop Day 1
Game Design and Development Workshop Day 1
 
Build a Game in 60 minutes
Build a Game in 60 minutesBuild a Game in 60 minutes
Build a Game in 60 minutes
 
Quick & Dirty & MEAN
Quick & Dirty & MEANQuick & Dirty & MEAN
Quick & Dirty & MEAN
 
A Quick Intro to ReactiveX
A Quick Intro to ReactiveXA Quick Intro to ReactiveX
A Quick Intro to ReactiveX
 

Kürzlich hochgeladen

eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slidesvaideheekore1
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profileakrivarotava
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencessuser9e7c64
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 

Kürzlich hochgeladen (20)

eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Introduction to Firebase Workshop Slides
Introduction to Firebase Workshop SlidesIntroduction to Firebase Workshop Slides
Introduction to Firebase Workshop Slides
 
SoftTeco - Software Development Company Profile
SoftTeco - Software Development Company ProfileSoftTeco - Software Development Company Profile
SoftTeco - Software Development Company Profile
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
Patterns for automating API delivery. API conference
Patterns for automating API delivery. API conferencePatterns for automating API delivery. API conference
Patterns for automating API delivery. API conference
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 

AngularJS Beginner Workshop

  • 1. Beginning AngularJS 13 & 14 June 2015, Cowork South Bay Troy Miles
  • 3. Troy Miles Over 35 years of programming experience Blog: http://therockncoder.blogspot.com/ Twitter: @therockncoder Email: rockncoder@gmail.com GitHub: https://github.com/Rockncoder
  • 4. Agenda Day One Introduction Tools Using Yeoman To Do App Testing Animation Services/Modules Controller As Filters
  • 5. Agenda Day Two Deployment Providers Contacts App $http & Promises $resource Testing ajax calls Firebase Custom Directives Wrap-up
  • 6. Lab #1 - Setup Check In the labs directory Launch the hello.html web page You should see a greeting displayed
  • 7. Lab Solution Browser expect web applications to be delivered via a web server While most browser will allow a web page to run from a file, most won’t allow it to access other files If your machine is setup correctly, you will see a greeting
  • 8. Lab #2 - jQuery Binding From the labs folder open the binding.html file Write JavaScript to transfer the text contents of the input tag with the id of firstName, to the span with the id of showName The code should be interactive and update as the user types Write you code in the empty script tag near the end of the page jQuery is already included on the page
  • 9. jQuery Example <!DOCTYPE html>
 <html>
 <head lang="en">
 <meta charset="UTF-8">
 <title>Binding</title>
 <script src="../lib/jquery-1.10.2.min.js"></script>
 </head>
 <body>
 <label for="firstName">Enter Your Name:</label>
 <input type="text" id="firstName"/>
 <h2>Display Your Name Below</h2>
 <label for="showName">Show Your Name:</label>
 <span id="showName"></span>
 
 <script>
 $( document ).ready( function(){
 $('#firstName').on("keyup", function(){
 $('#showName').text(this.value);
 });
 });
 </script>
 </body>
 </html>
  • 10. What’s Wrong with jQuery jQuery is a very popular library It is used on 50% of all web sites It is a library not a framework It is difficult code to test It can lead to the creation of spaghetti code
  • 11. AngularJS Example <!DOCTYPE html>
 <html ng-app>
 <head lang="en">
 <meta charset="UTF-8">
 <title>NG-Binding</title>
 <script src="../lib/angular.min.js"></script>
 </head>
 <body>
 <label>Enter Your Name:</label>
 <input type="text" ng-model="firstName"/>
 <h2>Display Your Name Below</h2>
 <label>Show Your Name:</label>
 <span>{{firstName}}</span>
 
 <script>
 </script>
 </body>
 </html>
  • 12. Strict Mode Strict mode allows you to opt in to a more restrictive version of JavaScript Things usually permitted in JS become errors Can be applied to an entire script or individual functions Strict mode is a JavaScript best practice
  • 13. Invoking Strict Mode Before any other statements place the following statement "use strict"; or 'use strict’; Works on both the script and function level Be careful of mixing strict and non-strict mode files
  • 15. Backbone.js Created by Jeremy Ashkenas in 2010 19 kb production version (minimized, not gzipped) One dependency - Underscore.js, optional jQuery Three core concepts: models, collections, & views Uses lots of custom events
  • 16. Knockout Created by Steve Sanderson in 2010 47 kb production version (minimized, not gzipped) Uses MVVM pattern Two way data-binding No dependencies Supports all mainstream browsers
  • 17. Ember Created by Yehuda Katz and Tom Dale in 2011 Convention over configuration Ember Data, a separate package, handles RESTful data Handlebars.js, a separate package, handles templates 337 kb production version (minimized, not gzipped)
  • 18. AngularJS Created by Miško Hevery and Adam Abrons in 2009 JavaScript MVC 106 kb production version (minimized, not gzipped) Declarative programming for UI Imperative programming for business logic
  • 19. AngularJS Key Features Two Way Data-binding Model View Controller Dependency Injection Deep Linking HTML Templates Directives Testability
  • 20. Two Way Data-binding In AngularJS, binding is built into the framework Replaces text content of HTML element with the value of the expression {{ expression }} <ANY ng-bind=“expression”>…</ANY> <ANY class=“ng-bind: expression;”>…</ANY>
  • 21. Model View Controller Uses MVC or MVVM or MV* depends on who you ask The goal is clear separation of concerns The model is only concerned with data The view presents the data to the user The controller applies the business logic
  • 22. Dependency Injection A software design pattern that implements inversion of control and allows a program design to follow the dependency inversion principle Allows a dependency to be passed to an object Allows code to clearly state dependencies Leads to code which is easier to debug and test Makes it possible to minimize apps without breaking them
  • 23. Deep Linking One feature that web sites have over desktop apps are bookmarks Deep linking allows AngularJS to restore state based on a URL Application can use hyperlinks to navigate users around
  • 24. HTML Templates There are a lot of templating libraries AngularJS instead uses HTML for its templates AngularJS templates can pass HTML validators Designers will feel at home Easy to learn
  • 25. Directives Possibly the best thing in AngularJS Directives extend the capabilities of HTML Merge the declarative nature of HTML to the imperative nature of JavaScript
  • 26. Testability AngularJS was engineered with testing in mind It supports both unit and integration tests For unit tests it works well with Jasmine Karma is the test runner
  • 27. npm Included with Node.js Installs many open source projects https://www.npmjs.com/
  • 28. Yeoman Kickstarts a new project Adheres to best practices Uses Generators http://yeoman.io/
  • 29. Bower Package manager for web applications Keeps track of your libraries like jQuery, Bootstrap, etc Dependencies kept in bower.json file http://bower.io/
  • 30. Grunt JavaScript Task Runner Does mundane work for you Hundreds of plugins available http://gruntjs.com/
  • 32. ng-bind vs ng-model ng-bind is one way data binding, aka output ng-bind renders a property on scope ng-bind has a shortcut {{}} ng-bind is preferred over shortcut ng-model is for two-way data binding ng-model is intended for form elements <input ng-model='userName' />
  • 33. Name Mangling There are basic incompatibilities between names used in HTML and those in JavaScript HTML permits dashes and colons, JavaScript does not To convert to JavaScript delete any initial x-, data- First letters after are capitalized delete dashes, underscores, and colons
  • 34. Name Mangling So all of the following attributes equal timePicker: data-time-picker x:time-picker time_picker
  • 35. Lab - Greet-o-matic Open the greet-o-magic.html file Make the page functional The user should be able to enter their name in either input tag and have it reflect in the other and in the span tag You shouldn’t need to write any JavaScript
  • 36. Two Way Data-binding <!DOCTYPE html>
 <html ng-app>
 <head lang="en">
 <meta charset="UTF-8">
 <title>Greet-o-matic</title>
 <link rel="stylesheet" href="../css/bootstrap.css"/>
 <script type="text/javascript" src="../libs/angular.js"></script>
 </head>
 <body>
 <div class="container" >
 <h1>Greet-o-matic</h1>
 <div class="col-lg-6">
 <input type="text" ng-model="userName" placeholder="Enter name here"/>
 </div>
 <div class="col-lg-6">
 <input type="text" ng-model="userName" placeholder="or over here"/>
 </div>
 <hr/>
 <p>Hello <span>{{userName}}</span>,<br/>Have a nice day!</p>
 </div>
 </body>
 </html>
  • 37. $scope An object which refers to the application model The glue between the controller and the view The execution context for expressions Provides APIs $watch - observes model $apply - propagates model changes to AngularJS
  • 38. Code Along - Todo App A Todo app is the hello world app of JavaScript MVC frameworks It shows how to create an app which creates, reads, updates, and deletes data (CRUD) Let’s build one together
  • 39. Code Along - Todo App Steps create shell page with angular link create script tag for JS add ng-app with module name ‘ToDo’ create angular module create todo controller create todos array create add method create delete method create complete method
  • 40. Code Along - Todo App Steps add markup add functionality to methods clear text box after added
  • 41. Jasmine Latest version 2.2, but we will be using 2.0.2 The default unit tester for AngularJS Others will also work Behavior Driven Development (BDD) approach
  • 42. Describe - test suite Describe is a global jasmine function Two params string - name of the test suite function - implementation of the suite Can be nested
  • 43. it - specs it is a global jasmine function Looks like describe A spec contains one or more expectations If all expectations true, it is a passing spec If any expectation fails, it is a failing spec
  • 44. Expectations Expect function One param The actual Chained to a Matcher function
  • 45. Matchers Take the output of the expect function and compare it to something Implement a boolean compare between actual value and expected Reports to Jasmine if the expectation is true or false Any matcher can be negated with a not before it
  • 46. Some matchers toBe - compares using === toEqual - works for literal variables and objects toMatch - for regular expressions toBeDefined - compares against 'undefined' toBeUndefined - also compares against ‘undefined'
  • 47. Some matchers (CONTINUE) toBeNull - compares against null toBeTruthy - truthy boolean casting toBeFalsy - falsy boolean casting toContain - finds an item in array
  • 48. Some matchers (CONTINUE) toBeLessThan toBeGreaterThan toBeCloseTo - precision math comparison toThrow - should throw an exception
  • 49. beforeEach / afterEach Are setup and teardown functions called before and after each spec it this beforeEach, it, and afterEach share the same this it is cleared before call spec call any beforeEach not included in a describe block is executed before any Jasmine test can use this to add custom matchers
  • 50. Disabling suites and specs prepend an 'x' before describe or it specs inside a disabled suite are not ran
  • 51. Unit Testing 3As Arrange - Set up object to be tested Act - Act on the object Assert - Test the state of the object
  • 52. TDD vs BDD Dev writes test Run tests - fail Implement tests in code Run tests - pass Refactor code Dev writes behavior and specs Run specs - fail Implement specs in code Run specs - pass Refactor code
  • 53. Views template - String contain HTML to display templateUrl - Relative URL of file holding HTML or id of DOM element holding HTML
  • 54. Inline View Template The id name in the script tag matches… templateUrl value of the route template stored in index.html or other HTML file 54 <script id="contact.html" type="text/ng-template">
 <h2>Contact</h2>
 <hr/>
 <p>For more information email rockncoder@gmail.com</p>
 <hr/>
 </script>
  • 55. Providers What are providers? Types of providers Services Factories Providers
  • 56. What are providers? Objects that are instantiated and wired together automatically by the injector service The injector creates two kinds of objects: services - defined by the developer specialized objects - Angular framework pieces, controllers, directives, filters, or animations
  • 58. Services Substitutable objects that are wired together using DI Used to organize and share code across app Only instantiated when an app component depends on it Singletons Built-in services always start with “$”
  • 59. Factories Introduction to shared components Dependency injection deep dive Building custom factories & services Persisting data to a Web API service
  • 60. Lab - ng-contacts We are going to super size the Todo app into a contacts We will Firebase as our backend We can develop locally and then deploy
  • 61. Firebase A powerful API to store and sync data in realtime Offer free developer accounts Both backend data and hosting No real arrays (limitation due to contention problem) Used by AngularJS.org site https://www.firebase.com/
  • 62. Firebase Data Limits A node's key max length 768 A node can't be nested deeper than 32 levels Any unicode character except .$[]/ plus the ASCII control keys of 0-31 and 127
  • 63. Firebase Sizes One child value - 100 mb UTF-8 encoded SDK write value max - 16 mb UTF-8 REST write value max - 100 mb UTF-8 Nodes in a read operation 100 million
  • 64. Firebase Writing Data set() Saves data to the specified Firebase reference Any existing data at the path is overwritten update() push() transaction
  • 65. Firebase Installation Add script tag for firebase Add script tag for AngularFire Add firebase.json file Create a firebase reference object
  • 66. Filters Understanding Filters A tour of built-in filters Building custom Filters Lab
  • 67. Understanding Filters Used to format data displayed to user Strictly front-end, doesn’t change model data Accessible using declarative or imperative syntax {{ expression [| filter_name[:parameter_value] ... ] }} $scope.originalText = 'hello';
 $scope.filteredText = $filter('uppercase') ($scope.originalText);
  • 68. A tour of built-in filters currency date json lowercase uppercase number filter limitTo orderBy
  • 69. Building custom filters tempApp.filter('minimum', [function () {
 return function (arrTemp, minimum) {
 var filteredArray = [];
 var min = minimum ? minimum : 15;
 angular.forEach(arrTemp, function (value, key) {
 if (value.temp >= min) filteredArray.push(value);
 });
 return filteredArray;
 };
 }]);

  • 70. Lab - Using Filters Let’s add a search filter to our contacts app
  • 71. Directives Introduction to Directives jQuery integration Using a jQuery UI Widget
  • 72. Directives Markers on a DOM element that attach a behavior to it Can be an attribute, element name, comment, or CSS The HTML compiler traverses the DOM at bootstrap and matches directives to DOM elements
  • 73. Directives Names <div timePicker></div> <div time-picker></div> <div time:picker></div> <div time_picker></div> <div x-time-picker></div> <div data-time-picker></div>
  • 74. Directive Location Tag name: <timePicker></timePicker> Attribute: <div data-rnc-time-picker></ div> Class: <div class=“time-picker;”></div> Comment: <!— directive:time-picker —>
  • 76. jQuery Integration AngularJS includes a mini version of jQuery called jqLite But it is perfectly compatible with the jQuery jQuery must be loaded before Angular or it won’t see it
  • 77. Using a jQuery Widget app.directive('timePicker', function () {
 var today = new Date(new Date().toDateString());
 return {
 require: '?ngModel',
 link: function ($scope, $element, $attrs, ngModel) {
 var initialized = false;
 
 ngModel = ngModel || {
 "$setViewValue": angular.noop
 };
 
 // where is the missing time value?
 setTimeout(function () {
 initialized = $element.timepicker()
 .on('changeTime', function (ev, ui) {
 var sec = $element.timepicker('getSecondsFromMidnight');
 ngModel.$setViewValue(sec * 1000);
 console.log("sec = " + sec);
 });
 });
 
 ngModel.$render = function (val) {
 if (!initialized) {
 //If $render gets called before our timepicker plugin is ready, just return
 return;
 }
 $element.timepicker('setTime', new Date(today.getTime() + val));
 }
 }
 }
 });
  • 78. Lab - jQuery UI Widget Let’s add a jQuery UI calendar widget to our contact app We will essentially wrap it to make it “angularized”
  • 79. Summary Modern Web Apps Compared AngularJS’ way to jQuery’s AngularJS’ Core Concepts Controllers Todo App Contacts App
  • 81. Troy Miles Over 30 years of programming experience Blog: http://therockncoder.blogspot.com/ Twitter: @therockncoder Email: rockncoder@gmail.com GitHub: https://github.com/Rockncoder