SlideShare a Scribd company logo
1 of 45
Angular 2 for Beginners
Oswald Campesato
Consultant/Training:
www.iquarkt.com
ocampesato@yahoo.com
Features of Angular 2 (part 1)
• Beta status
• component-based architecture
• loosely coupled components
• less code more application focus
• "Mobile First" approach
• Angular 2 Github repository:
https://github.com/angular.io
Features of Angular 2 (part 2)
• Angular 2 can be 5x faster than Angular 1.x
• One-way data binding (by default)
• Two-way data binding (optional)
• Dependency injection
• Support for ES5/ES6/TypeScript
• Performance comparable to React(?)
Ang1.x features removed from Ang 2
+ $scope
+ factories
+ controllers
+ providers
+ $apply
+ $digest
+ many built-in directives
What are Transpilers?
• They convert code from one language to another
• Babel (formerly 6to5):
+converts ES6 (some ES7) to ECMA5
+ appears to be the de facto standard
• Traceur (Google):
+ converts ES6 to ECMA5
+ used by Angular 2
TypeScript (MicroSoft): http://www.TypeScriptlang.org
Angular 2 App (index.html)
<script
src="https://rawgithub.com/systemjs/systemjs/0.19.6/dist/system.
js"></script>
<script
src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2-
polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-
beta.0/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-
Angular 2 Support Libraries
• 1) ES6 Shim:
• shims for older JavaScript engines
• for ECMAScript 6 emulation
• 2) Angular 2 Polyfills:
• code for zones, promises, and reflection
• 3) SystemJS:
• a module loader
•
• 4) RxJS:
• a library for reactive programming in JS
• supports Observables: emit streams of data
• Angular uses Observables for asynch code (HTTP requests)
Angular 2 and TypeScript
• TypeScript classes (transpiled to ES5)
• @ symbol for annotations/decorators
• @Component (selector, template, … )
• class MyApp{} (or some other name of your choice)
• Bootstrapping the ‘root’ component:
bootstrap(MyApp)
Angular 2 Example (app/main.ts)
• import {bootstrap} from 'angular2/platform/browser';
• import {Component} from 'angular2/core';
• @Component({
• selector: 'my-app',
• template: `<div>Hello from Angular 2</div>`
• })
• class MyApp {}
• bootstrap(MyApp);
Download/Install Code Samples
• 1) download/unzip Github repo (or clone repo)
• 2) npm install
• 3) python –m SimpleHTTPServer (or equivalent)
• 4) go to http://localhost:8000
• Command-line compilation (optional): tsc
• Watch for changes (optional): tsc --watch
Add Some Data (app/main.ts)
• import {bootstrap} from 'angular2/platform/browser';
• import {Component} from 'angular2/core';
• @Component({
• selector: 'my-app',
• template: `<div>{{ city }}</div>`
• })
• class MyApp {
• city:string;
• constructor() {
• this.city = ‘New York’;
• }
• }
• bootstrap(MyApp);
Exercise: Add More Data (main.ts)
• Add a first name field
• Add a last name field
• Add a state field
• reload the application
ng-repeat vs *ngFor
• Angular 1.x "ng-repeat":
<ul>
<li ng-repeat="user in users">
<h2>{{user}</h2>
</li>
</ul>
• Angular 2 "*ngFor":
<ul>
<li *ngFor="#user of users">
<h2>{{user}}</h2>
</li>
</ul>
Display List of Users (app/main.ts)
• import {bootstrap} from 'angular2/platform/browser';
• import {Component} from 'angular2/core';
• @Component({
• selector: 'my-app',
• template: `<div><ul>
• <li *ngFor='user of users'> {{ user }} </li>
• </ul></div>`
• })
• class MyApp {
• users:string[]; // or users:Array<string>;
• constructor() {
• this.users = ['Jane', 'Dave', 'Tom'];
• }
• }
• bootstrap(MyApp);
Exercise: Display User data with ngFor
• Modify the array to support literal objects
• Include first name/last name/city properties
• Display three properties in an unordered list
• reload the application
Angular 2 and Event Objects
• <button (click)="clicked($event)"></button>
@Component(...)
class MyApp {
clicked(event) {
event.preventDefault();
// do stuff here
console.log("you clicked me");
}
}
bootstrap(MyApp);
Angular 2 Template Syntax
• [attribute] syntax:
<input [value]="name">
• (method) syntax:
<input #myname (keyup)="vm.myCtrlMethod()">
• ^ symbol handles bubble up events:
<div (^click)="handleClick()">
<div></div>
</div>
• [(method)] syntax for two-way binding:
<input [(ng-model)]="vm.foo">
<p>Hello {{vm.foo}}</p>
Angular 2 Built-in Components
• NgIf
• NgSwitch
• NgStyle
• NgClass
• NgFor
• NgNonBindable
What about ES6?
• Arrow functions and let keyword
• Block scopes
• Classes and inheritance
• Default parameters
• Destructured assignment
• Generators, Iterators, Maps, and Sets
• Promises and Rest parameters
• Spread operator
• Template Literals
ES6 let and Arrow Functions
• let square = x => x * x;
• let add = (x, y) => x + y;
• let pi = () => 3.1415;
• console.log(square(8)); // 64
• console.log(add(5, 9)); // 14
• console.log(pi()); // 3.1415
ES6 Class Definition (part 1)
class Rectangle {
constructor(height, width) {
this.height = height;
this.width = width;
}
calcArea() {
return this.height * this.width;
}
}
• var r1 = new Rectangle(5,10);
• var r2 = new Rectangle(25,15);
ES6 Class Definition (part 2)
• console.log("r1 area = "+r1.calcArea());
• console.log("r2 area = "+r2.calcArea());
• Test this code here:
http://babeljs.io/repl/
• More Examples:
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/Reference/Classes
What is TypeScript?
• A superset of JavaScript (ES6): 10/01/2012
• A compiled language (tsc compiler)
• strong typing and also type inferencing
• Type checking during compile time
• "minimal" extra compile time overhead
• ".ts" files are transpiled into ".js" files (via tsc)
• "lib.d.ts" contains TypeScript definitions
• TypeScript type definitions (update via "nuget"):
https://github.com/borisyankov/DefinitelyTyped
TypeScript Improvements over ES5
• Types
• Classes
• Annotations
• Imports
• language utilities (e.g. destructuring)
Other TypeScript Features
• Interfaces
• Inheritance
• Generics
TypeScript Variables
• var isDone: boolean = false;
• var height: number = 6;
• var name: string = "dave";
• var myList:number[] = [1, 2, 3]; // option #1
• var myList:Array<number> = [1, 2, 3]; // option #2
• var changeMe: any = 4;
• changeMe = ”I’m a string now";
• var myList:any[] = [1, true, ”pizza"];
TypeScript Functions
• void return type:
function myLogger(msg?:string): void {
console.log("My custom logger: “+msg);
}
• Generics:
function identity<T>(arg: T): T {
return arg;
}
// output has 'string' type (explicit/inferred):
var output = identity<string>("Dave");
var output = identity("Dave");
TypeScript "any" Type
• any return type:
• function selectSomething(x): any {
• if (typeof x == "object") {
• return 10;
• } else {
• return "abc";
• }
• }
NB: "any" type disables type checking
NB: you can disallow implicit "any" in Visual Studio
Functions vs Lambda Expressions
• JavaScript Function:
var doubleJS = function(x) { return 2*x; }
• TypeScript Function:
var doubleTS = function(x:number) {return 2*x;}
• Lambda versions of the TypeScript function:
var lambdaTS = (x:number) => 2*x;
var lambdaTS = x => 2*x;
Another Lambda function:
var x = function(delay:number, () =>void) {
// timer code
});
TypeScript Interfaces
interface User {
name: string;
weight?: number; // optional
}
function displayUser(user: User) {
console.log(user.name);
}
• This works even without "weight" in the interface:
var aUser = {name: "John Smith", weight:200};
displayUser(aUser);
TypeScript Class (part 1)
class User {
fname: string;
lname: string;
constructor(fname:string, lname:string) {
this.fname = fname;
this.lname = lname;
}
fullname():string {
return this.fname+" "+this.lname;
}
}
TypeScript Class (part 2)
• var u1:User, u2:User;
• u1 = new User("Jane", "Smith");
• u2 = new User("John", "Jones");
• console.log("user1 = "+u1.fullname());
• console.log("user2 = "+u2.fullname());
• Exercise: use an interface in class User
• Aside: use interfaces as arguments of public methods
(whenever possible) instead of using standard JS/TS types or
class instances
Convert JSON Data to TS Class (1)
• Consider the following array of data:
var people = [
{fname:"Jane",lname:"Smith",zip:"94043"},
{fname:"John",lname:"Jones",zip:"94539"},
{fname:"Dave",lname:"Starr",zip:"67800"}
]
Convert JSON Data to TS Class (2)
class People {
• public fname:string;
• public lname:string;
• public zip:string;
• constructor(public fname:string,
• public lname:string,
• public zip:string) {
• this.fname = fname;
• this.lname = lname;
• this.zip = zip;
• }
}
Convert JSON Data to TS Class (3)
• Array of TypeScript objects:
var TSPeople = [
new People("Jane","Smith","94043"),
new People("John","Jones","94539"),
new People("Dave","Starr","67800")
];
TypeScript and the this keyword
• The this keyword is contextually bound in the same
fashion as standard JS functions
• The this keyword is lexically bound in Lamba functions
so it’s automatically captured (emitted JS uses _this)
• Typically based on how the function is called
• More information about the this keyword:
https://tinyurl.com/MDNthis
Migrating JS "classes" to TypeScript
• Option #1: Annotate with an interface:
+Interface and impl are synchronized manually
+Faster initially and lower risk
• Option #2: Refactor as a class:
+More initial code changes
+More maintainable and semantic
http://www.typescriptlang.org/Handbook
What Should I Learn???
• Main features of ES6 and TypeScript 1.6+
• "basic" Angular 1.5+ and 2 (best practices)
• Practice converting code from ANG 1.x to 2
• Select an IDE:
+WebStorm 10: free 30-day trial ($49/year)
+Visual Studio Code (free)
+ Atom (free) with atom-TypeScript extension
• Command Line Tools:
+ npm, npmjs, gulp, grunt (older), broccoli,
+ webpack, browserify (older), jspm+systemjs
https://github.com/addyosmani/es6-tools
Other Technologies to Learn
• Sass/Bootstrap 4 (previous: less)
• HandleBars/Nunjucks (previous: Jade/EJS)
• Material Design (and MDL)
• Firebase/AngularFire
• D3.js for Data Visualization
• Ionic (=Angular for Mobile)
Browser Status for ES6
• Modern IE: https://goo.gl/56n7IL
• Mozilla: https://goo.gl/iSNDf9
• Chrome: https://www.chromestatus.com/features#ES6
Other Useful ES6 Links
https://github.com/lukehoban/es6features
http://kangax.github.io/compat-table/es6/
https://dev.modern.ie/platform/status/?filter=f3f0000bf&search=es6
https://developer.mozilla.org/en-
US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_i
n_Mozilla
https://medium.com/@bojzi/overview-of-the-javascript-ecosystem-
8ec4a0b7a7be
More Useful Links
• Change detection in Angular 2:
https://github.com/angular/watchtower.js
http://zone.js/
http://victorsavkin.com/post/110170125256/change-detection-in-
angular-2
• Angular scaffolding:
https://github.com/DaftMonk/generator-angular-fullstack
https://github.com/yeoman/generator-angular
http://lauterry.github.io/ngTailor/
• Touch animations:
https://docs.google.com/document/d/16Z6Lun15DoWNrE2imk7N-
2WiRAaqc954LOfU2-2JSoI/edit#heading=h.rcjxs836qiki
Angular Tutorials
• Getting started with Angular 2:
https://docs.google.com/document/d/1MkpvTNfmxHwdSv9rQyQIvjR
LnoGk4rvkNMkOEWTPkCw/edit#heading=h.6z1yv9f94fuv
• Building Angular Apps using Flux:
https://docs.google.com/document/d/16axBamHEZORS_KJZDjahLuhk
hUuNVt77ZcGRoRiyjfQ/edit
New features in Angular 1.4:
• https://docs.google.com/document/d/1BkDxdkzB5JmQBgpLKEkGY
92pWF9Xr89cSLltPJVdHC0/edit
Future Work in Angular 2
• Server-side rendering
• Web Workers
• smooth and responsive UI
• Native mobile UI (see Ionic for mobile)
• Compile as build step
Recent/Upcoming Books and Training
1) HTML5 Canvas and CSS3 Graphics (2013)
2) jQuery, CSS3, and HTML5 for Mobile (2013)
3) HTML5 Pocket Primer (2013)
4) jQuery Pocket Primer (2013)
5) HTML5 Mobile Pocket Primer (2014)
6) D3 Pocket Primer (2015)
7) Python Pocket Primer (2015)
8) SVG Pocket Primer (2016)
9) CSS3 Pocket Primer (2016)
10) Angular Pocket Primer (2016)

More Related Content

What's hot

Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Ahmed Moawad
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Knoldus Inc.
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework Yakov Fain
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Sumanth Chinthagunta
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developersYakov Fain
 
Angular Weekend
Angular WeekendAngular Weekend
Angular WeekendTroy Miles
 
Angular 2: What's New?
Angular 2: What's New?Angular 2: What's New?
Angular 2: What's New?jbandi
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation Phan Tuan
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2Naveen Pete
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Codemotion
 
An introduction to Angular2
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2 Apptension
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular jsAndrew Alpert
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian MüllerSebastian Holstein
 
Angular 2 어디까지 왔을까
Angular 2 어디까지 왔을까Angular 2 어디까지 왔을까
Angular 2 어디까지 왔을까장현 한
 

What's hot (20)

Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1Exploring Angular 2 - Episode 1
Exploring Angular 2 - Episode 1
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Angular2
Angular2Angular2
Angular2
 
Angular 5
Angular 5Angular 5
Angular 5
 
Overview of the AngularJS framework
Overview of the AngularJS framework Overview of the AngularJS framework
Overview of the AngularJS framework
 
Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0 Single Page Applications with AngularJS 2.0
Single Page Applications with AngularJS 2.0
 
Angular2 Development for Java developers
Angular2 Development for Java developersAngular2 Development for Java developers
Angular2 Development for Java developers
 
Angular Weekend
Angular WeekendAngular Weekend
Angular Weekend
 
Angular 2: What's New?
Angular 2: What's New?Angular 2: What's New?
Angular 2: What's New?
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
AngularJS2 / TypeScript / CLI
AngularJS2 / TypeScript / CLIAngularJS2 / TypeScript / CLI
AngularJS2 / TypeScript / CLI
 
Introduction to Angularjs
Introduction to AngularjsIntroduction to Angularjs
Introduction to Angularjs
 
Introduction to Angular 2
Introduction to Angular 2Introduction to Angular 2
Introduction to Angular 2
 
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
Universal JavaScript Web Applications with React - Luciano Mammino - Codemoti...
 
An introduction to Angular2
An introduction to Angular2 An introduction to Angular2
An introduction to Angular2
 
Building scalable applications with angular js
Building scalable applications with angular jsBuilding scalable applications with angular js
Building scalable applications with angular js
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Data Flow Patterns in Angular 2 - Sebastian Müller
Data Flow Patterns in Angular 2 -  Sebastian MüllerData Flow Patterns in Angular 2 -  Sebastian Müller
Data Flow Patterns in Angular 2 - Sebastian Müller
 
Angular js
Angular jsAngular js
Angular js
 
Angular 2 어디까지 왔을까
Angular 2 어디까지 왔을까Angular 2 어디까지 왔을까
Angular 2 어디까지 왔을까
 

Similar to Angular2 for Beginners

Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CAlexis Gallagher
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileAmazon Web Services Japan
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN StackTroy Miles
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almostQuinton Sheppard
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basicsLovelitJose
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたTaro Matsuzawa
 
React Native Evening
React Native EveningReact Native Evening
React Native EveningTroy Miles
 
A la découverte de TypeScript
A la découverte de TypeScriptA la découverte de TypeScript
A la découverte de TypeScriptDenis Voituron
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoMatt Stine
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scalaXing
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghStuart Roebuck
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)Eduard Tomàs
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016Codemotion
 
JavaScript in 2015
JavaScript in 2015JavaScript in 2015
JavaScript in 2015Igor Laborie
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...GeeksLab Odessa
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonAlex Payne
 

Similar to Angular2 for Beginners (20)

Angular2 inter3
Angular2 inter3Angular2 inter3
Angular2 inter3
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Swift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-CSwift, functional programming, and the future of Objective-C
Swift, functional programming, and the future of Objective-C
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
 
React Development with the MERN Stack
React Development with the MERN StackReact Development with the MERN Stack
React Development with the MERN Stack
 
React inter3
React inter3React inter3
React inter3
 
Awesomeness of JavaScript…almost
Awesomeness of JavaScript…almostAwesomeness of JavaScript…almost
Awesomeness of JavaScript…almost
 
Programming in java basics
Programming in java  basicsProgramming in java  basics
Programming in java basics
 
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみたスマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
スマートフォン勉強会@関東 #11 どう考えてもdisconなものをiPhoneに移植してみた
 
React Native Evening
React Native EveningReact Native Evening
React Native Evening
 
A la découverte de TypeScript
A la découverte de TypeScriptA la découverte de TypeScript
A la découverte de TypeScript
 
ReactJS for Beginners
ReactJS for BeginnersReactJS for Beginners
ReactJS for Beginners
 
A Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to GoA Recovering Java Developer Learns to Go
A Recovering Java Developer Learns to Go
 
An introduction to scala
An introduction to scalaAn introduction to scala
An introduction to scala
 
Scala @ TechMeetup Edinburgh
Scala @ TechMeetup EdinburghScala @ TechMeetup Edinburgh
Scala @ TechMeetup Edinburgh
 
JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)JavaScript in 2016 (Codemotion Rome)
JavaScript in 2016 (Codemotion Rome)
 
JavaScript in 2016
JavaScript in 2016JavaScript in 2016
JavaScript in 2016
 
JavaScript in 2015
JavaScript in 2015JavaScript in 2015
JavaScript in 2015
 
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
Java/Scala Lab: Анатолий Кметюк - Scala SubScript: Алгебра для реактивного пр...
 
Emerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the HorizonEmerging Languages: A Tour of the Horizon
Emerging Languages: A Tour of the Horizon
 

More from Oswald Campesato

Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)Oswald Campesato
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasOswald Campesato
 
Introduction to Deep Learning
Introduction to Deep LearningIntroduction to Deep Learning
Introduction to Deep LearningOswald Campesato
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2Oswald Campesato
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2Oswald Campesato
 
"An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning""An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning"Oswald Campesato
 
Introduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowIntroduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowOswald Campesato
 
Introduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-ProgrammersIntroduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-ProgrammersOswald Campesato
 
TensorFlow in Your Browser
TensorFlow in Your BrowserTensorFlow in Your Browser
TensorFlow in Your BrowserOswald Campesato
 
Deep Learning in Your Browser
Deep Learning in Your BrowserDeep Learning in Your Browser
Deep Learning in Your BrowserOswald Campesato
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlowOswald Campesato
 
Introduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlowIntroduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlowOswald Campesato
 
Intro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.jsIntro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.jsOswald Campesato
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlowOswald Campesato
 
Introduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowIntroduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowOswald Campesato
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and SparkOswald Campesato
 
Deep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGLDeep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGLOswald Campesato
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowOswald Campesato
 

More from Oswald Campesato (20)

Working with tf.data (TF 2)
Working with tf.data (TF 2)Working with tf.data (TF 2)
Working with tf.data (TF 2)
 
Introduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and KerasIntroduction to TensorFlow 2 and Keras
Introduction to TensorFlow 2 and Keras
 
Introduction to Deep Learning
Introduction to Deep LearningIntroduction to Deep Learning
Introduction to Deep Learning
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
Introduction to TensorFlow 2
Introduction to TensorFlow 2Introduction to TensorFlow 2
Introduction to TensorFlow 2
 
"An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning""An Introduction to AI and Deep Learning"
"An Introduction to AI and Deep Learning"
 
H2 o berkeleydltf
H2 o berkeleydltfH2 o berkeleydltf
H2 o berkeleydltf
 
Introduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and TensorflowIntroduction to Deep Learning, Keras, and Tensorflow
Introduction to Deep Learning, Keras, and Tensorflow
 
Introduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-ProgrammersIntroduction to Deep Learning for Non-Programmers
Introduction to Deep Learning for Non-Programmers
 
TensorFlow in Your Browser
TensorFlow in Your BrowserTensorFlow in Your Browser
TensorFlow in Your Browser
 
Deep Learning in Your Browser
Deep Learning in Your BrowserDeep Learning in Your Browser
Deep Learning in Your Browser
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlow
 
Introduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlowIntroduction to Deep Learning and TensorFlow
Introduction to Deep Learning and TensorFlow
 
Intro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.jsIntro to Deep Learning, TensorFlow, and tensorflow.js
Intro to Deep Learning, TensorFlow, and tensorflow.js
 
Deep Learning and TensorFlow
Deep Learning and TensorFlowDeep Learning and TensorFlow
Deep Learning and TensorFlow
 
Introduction to Deep Learning and Tensorflow
Introduction to Deep Learning and TensorflowIntroduction to Deep Learning and Tensorflow
Introduction to Deep Learning and Tensorflow
 
Deep Learning, Scala, and Spark
Deep Learning, Scala, and SparkDeep Learning, Scala, and Spark
Deep Learning, Scala, and Spark
 
Deep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGLDeep Learning in your Browser: powered by WebGL
Deep Learning in your Browser: powered by WebGL
 
Deep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlowDeep Learning, Keras, and TensorFlow
Deep Learning, Keras, and TensorFlow
 
C++ and Deep Learning
C++ and Deep LearningC++ and Deep Learning
C++ and Deep Learning
 

Recently uploaded

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...Health
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️anilsa9823
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdfWave PLM
 

Recently uploaded (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online  ☂️
CALL ON ➥8923113531 🔝Call Girls Kakori Lucknow best sexual service Online ☂️
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 

Angular2 for Beginners

  • 1. Angular 2 for Beginners Oswald Campesato Consultant/Training: www.iquarkt.com ocampesato@yahoo.com
  • 2. Features of Angular 2 (part 1) • Beta status • component-based architecture • loosely coupled components • less code more application focus • "Mobile First" approach • Angular 2 Github repository: https://github.com/angular.io
  • 3. Features of Angular 2 (part 2) • Angular 2 can be 5x faster than Angular 1.x • One-way data binding (by default) • Two-way data binding (optional) • Dependency injection • Support for ES5/ES6/TypeScript • Performance comparable to React(?)
  • 4. Ang1.x features removed from Ang 2 + $scope + factories + controllers + providers + $apply + $digest + many built-in directives
  • 5. What are Transpilers? • They convert code from one language to another • Babel (formerly 6to5): +converts ES6 (some ES7) to ECMA5 + appears to be the de facto standard • Traceur (Google): + converts ES6 to ECMA5 + used by Angular 2 TypeScript (MicroSoft): http://www.TypeScriptlang.org
  • 6. Angular 2 App (index.html) <script src="https://rawgithub.com/systemjs/systemjs/0.19.6/dist/system. js"></script> <script src="https://code.angularjs.org/tools/typescript.js"></script> <script src="https://code.angularjs.org/2.0.0-beta.0/angular2- polyfills.js"></script> <script src="https://code.angularjs.org/2.0.0- beta.0/Rx.js"></script> <script src="https://code.angularjs.org/2.0.0-
  • 7. Angular 2 Support Libraries • 1) ES6 Shim: • shims for older JavaScript engines • for ECMAScript 6 emulation • 2) Angular 2 Polyfills: • code for zones, promises, and reflection • 3) SystemJS: • a module loader • • 4) RxJS: • a library for reactive programming in JS • supports Observables: emit streams of data • Angular uses Observables for asynch code (HTTP requests)
  • 8. Angular 2 and TypeScript • TypeScript classes (transpiled to ES5) • @ symbol for annotations/decorators • @Component (selector, template, … ) • class MyApp{} (or some other name of your choice) • Bootstrapping the ‘root’ component: bootstrap(MyApp)
  • 9. Angular 2 Example (app/main.ts) • import {bootstrap} from 'angular2/platform/browser'; • import {Component} from 'angular2/core'; • @Component({ • selector: 'my-app', • template: `<div>Hello from Angular 2</div>` • }) • class MyApp {} • bootstrap(MyApp);
  • 10. Download/Install Code Samples • 1) download/unzip Github repo (or clone repo) • 2) npm install • 3) python –m SimpleHTTPServer (or equivalent) • 4) go to http://localhost:8000 • Command-line compilation (optional): tsc • Watch for changes (optional): tsc --watch
  • 11. Add Some Data (app/main.ts) • import {bootstrap} from 'angular2/platform/browser'; • import {Component} from 'angular2/core'; • @Component({ • selector: 'my-app', • template: `<div>{{ city }}</div>` • }) • class MyApp { • city:string; • constructor() { • this.city = ‘New York’; • } • } • bootstrap(MyApp);
  • 12. Exercise: Add More Data (main.ts) • Add a first name field • Add a last name field • Add a state field • reload the application
  • 13. ng-repeat vs *ngFor • Angular 1.x "ng-repeat": <ul> <li ng-repeat="user in users"> <h2>{{user}</h2> </li> </ul> • Angular 2 "*ngFor": <ul> <li *ngFor="#user of users"> <h2>{{user}}</h2> </li> </ul>
  • 14. Display List of Users (app/main.ts) • import {bootstrap} from 'angular2/platform/browser'; • import {Component} from 'angular2/core'; • @Component({ • selector: 'my-app', • template: `<div><ul> • <li *ngFor='user of users'> {{ user }} </li> • </ul></div>` • }) • class MyApp { • users:string[]; // or users:Array<string>; • constructor() { • this.users = ['Jane', 'Dave', 'Tom']; • } • } • bootstrap(MyApp);
  • 15. Exercise: Display User data with ngFor • Modify the array to support literal objects • Include first name/last name/city properties • Display three properties in an unordered list • reload the application
  • 16. Angular 2 and Event Objects • <button (click)="clicked($event)"></button> @Component(...) class MyApp { clicked(event) { event.preventDefault(); // do stuff here console.log("you clicked me"); } } bootstrap(MyApp);
  • 17. Angular 2 Template Syntax • [attribute] syntax: <input [value]="name"> • (method) syntax: <input #myname (keyup)="vm.myCtrlMethod()"> • ^ symbol handles bubble up events: <div (^click)="handleClick()"> <div></div> </div> • [(method)] syntax for two-way binding: <input [(ng-model)]="vm.foo"> <p>Hello {{vm.foo}}</p>
  • 18. Angular 2 Built-in Components • NgIf • NgSwitch • NgStyle • NgClass • NgFor • NgNonBindable
  • 19. What about ES6? • Arrow functions and let keyword • Block scopes • Classes and inheritance • Default parameters • Destructured assignment • Generators, Iterators, Maps, and Sets • Promises and Rest parameters • Spread operator • Template Literals
  • 20. ES6 let and Arrow Functions • let square = x => x * x; • let add = (x, y) => x + y; • let pi = () => 3.1415; • console.log(square(8)); // 64 • console.log(add(5, 9)); // 14 • console.log(pi()); // 3.1415
  • 21. ES6 Class Definition (part 1) class Rectangle { constructor(height, width) { this.height = height; this.width = width; } calcArea() { return this.height * this.width; } } • var r1 = new Rectangle(5,10); • var r2 = new Rectangle(25,15);
  • 22. ES6 Class Definition (part 2) • console.log("r1 area = "+r1.calcArea()); • console.log("r2 area = "+r2.calcArea()); • Test this code here: http://babeljs.io/repl/ • More Examples: https://developer.mozilla.org/en- US/docs/Web/JavaScript/Reference/Classes
  • 23. What is TypeScript? • A superset of JavaScript (ES6): 10/01/2012 • A compiled language (tsc compiler) • strong typing and also type inferencing • Type checking during compile time • "minimal" extra compile time overhead • ".ts" files are transpiled into ".js" files (via tsc) • "lib.d.ts" contains TypeScript definitions • TypeScript type definitions (update via "nuget"): https://github.com/borisyankov/DefinitelyTyped
  • 24. TypeScript Improvements over ES5 • Types • Classes • Annotations • Imports • language utilities (e.g. destructuring)
  • 25. Other TypeScript Features • Interfaces • Inheritance • Generics
  • 26. TypeScript Variables • var isDone: boolean = false; • var height: number = 6; • var name: string = "dave"; • var myList:number[] = [1, 2, 3]; // option #1 • var myList:Array<number> = [1, 2, 3]; // option #2 • var changeMe: any = 4; • changeMe = ”I’m a string now"; • var myList:any[] = [1, true, ”pizza"];
  • 27. TypeScript Functions • void return type: function myLogger(msg?:string): void { console.log("My custom logger: “+msg); } • Generics: function identity<T>(arg: T): T { return arg; } // output has 'string' type (explicit/inferred): var output = identity<string>("Dave"); var output = identity("Dave");
  • 28. TypeScript "any" Type • any return type: • function selectSomething(x): any { • if (typeof x == "object") { • return 10; • } else { • return "abc"; • } • } NB: "any" type disables type checking NB: you can disallow implicit "any" in Visual Studio
  • 29. Functions vs Lambda Expressions • JavaScript Function: var doubleJS = function(x) { return 2*x; } • TypeScript Function: var doubleTS = function(x:number) {return 2*x;} • Lambda versions of the TypeScript function: var lambdaTS = (x:number) => 2*x; var lambdaTS = x => 2*x; Another Lambda function: var x = function(delay:number, () =>void) { // timer code });
  • 30. TypeScript Interfaces interface User { name: string; weight?: number; // optional } function displayUser(user: User) { console.log(user.name); } • This works even without "weight" in the interface: var aUser = {name: "John Smith", weight:200}; displayUser(aUser);
  • 31. TypeScript Class (part 1) class User { fname: string; lname: string; constructor(fname:string, lname:string) { this.fname = fname; this.lname = lname; } fullname():string { return this.fname+" "+this.lname; } }
  • 32. TypeScript Class (part 2) • var u1:User, u2:User; • u1 = new User("Jane", "Smith"); • u2 = new User("John", "Jones"); • console.log("user1 = "+u1.fullname()); • console.log("user2 = "+u2.fullname()); • Exercise: use an interface in class User • Aside: use interfaces as arguments of public methods (whenever possible) instead of using standard JS/TS types or class instances
  • 33. Convert JSON Data to TS Class (1) • Consider the following array of data: var people = [ {fname:"Jane",lname:"Smith",zip:"94043"}, {fname:"John",lname:"Jones",zip:"94539"}, {fname:"Dave",lname:"Starr",zip:"67800"} ]
  • 34. Convert JSON Data to TS Class (2) class People { • public fname:string; • public lname:string; • public zip:string; • constructor(public fname:string, • public lname:string, • public zip:string) { • this.fname = fname; • this.lname = lname; • this.zip = zip; • } }
  • 35. Convert JSON Data to TS Class (3) • Array of TypeScript objects: var TSPeople = [ new People("Jane","Smith","94043"), new People("John","Jones","94539"), new People("Dave","Starr","67800") ];
  • 36. TypeScript and the this keyword • The this keyword is contextually bound in the same fashion as standard JS functions • The this keyword is lexically bound in Lamba functions so it’s automatically captured (emitted JS uses _this) • Typically based on how the function is called • More information about the this keyword: https://tinyurl.com/MDNthis
  • 37. Migrating JS "classes" to TypeScript • Option #1: Annotate with an interface: +Interface and impl are synchronized manually +Faster initially and lower risk • Option #2: Refactor as a class: +More initial code changes +More maintainable and semantic http://www.typescriptlang.org/Handbook
  • 38. What Should I Learn??? • Main features of ES6 and TypeScript 1.6+ • "basic" Angular 1.5+ and 2 (best practices) • Practice converting code from ANG 1.x to 2 • Select an IDE: +WebStorm 10: free 30-day trial ($49/year) +Visual Studio Code (free) + Atom (free) with atom-TypeScript extension • Command Line Tools: + npm, npmjs, gulp, grunt (older), broccoli, + webpack, browserify (older), jspm+systemjs https://github.com/addyosmani/es6-tools
  • 39. Other Technologies to Learn • Sass/Bootstrap 4 (previous: less) • HandleBars/Nunjucks (previous: Jade/EJS) • Material Design (and MDL) • Firebase/AngularFire • D3.js for Data Visualization • Ionic (=Angular for Mobile)
  • 40. Browser Status for ES6 • Modern IE: https://goo.gl/56n7IL • Mozilla: https://goo.gl/iSNDf9 • Chrome: https://www.chromestatus.com/features#ES6
  • 41. Other Useful ES6 Links https://github.com/lukehoban/es6features http://kangax.github.io/compat-table/es6/ https://dev.modern.ie/platform/status/?filter=f3f0000bf&search=es6 https://developer.mozilla.org/en- US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_6_support_i n_Mozilla https://medium.com/@bojzi/overview-of-the-javascript-ecosystem- 8ec4a0b7a7be
  • 42. More Useful Links • Change detection in Angular 2: https://github.com/angular/watchtower.js http://zone.js/ http://victorsavkin.com/post/110170125256/change-detection-in- angular-2 • Angular scaffolding: https://github.com/DaftMonk/generator-angular-fullstack https://github.com/yeoman/generator-angular http://lauterry.github.io/ngTailor/ • Touch animations: https://docs.google.com/document/d/16Z6Lun15DoWNrE2imk7N- 2WiRAaqc954LOfU2-2JSoI/edit#heading=h.rcjxs836qiki
  • 43. Angular Tutorials • Getting started with Angular 2: https://docs.google.com/document/d/1MkpvTNfmxHwdSv9rQyQIvjR LnoGk4rvkNMkOEWTPkCw/edit#heading=h.6z1yv9f94fuv • Building Angular Apps using Flux: https://docs.google.com/document/d/16axBamHEZORS_KJZDjahLuhk hUuNVt77ZcGRoRiyjfQ/edit New features in Angular 1.4: • https://docs.google.com/document/d/1BkDxdkzB5JmQBgpLKEkGY 92pWF9Xr89cSLltPJVdHC0/edit
  • 44. Future Work in Angular 2 • Server-side rendering • Web Workers • smooth and responsive UI • Native mobile UI (see Ionic for mobile) • Compile as build step
  • 45. Recent/Upcoming Books and Training 1) HTML5 Canvas and CSS3 Graphics (2013) 2) jQuery, CSS3, and HTML5 for Mobile (2013) 3) HTML5 Pocket Primer (2013) 4) jQuery Pocket Primer (2013) 5) HTML5 Mobile Pocket Primer (2014) 6) D3 Pocket Primer (2015) 7) Python Pocket Primer (2015) 8) SVG Pocket Primer (2016) 9) CSS3 Pocket Primer (2016) 10) Angular Pocket Primer (2016)