SlideShare a Scribd company logo
1 of 37
Intro to AngularJS 
ANGULAR BY WAY OF KNOCKOUTJS AND OBSERVABLE PROGRAMMING
ngAgenda 
 Brief History on Observable Programming 
 Brief introduction to observable Javascript using KnockoutJS 
 Single Page App (SPA) Architecture 
 Comparison to roundtrip-based app 
 High-level Overview of AngularJS Fundamentals 
 Introduction to MVC in AngularJS 
 1 Rule: Please don’t debate my slides or demos! Save it for the after party =D 
 But I love questions! 
 Embrace “ng” – everything in the Angular world is preceded by “ng” 
 Oh, and find the error for a prize! Call them out as you see them 
Brief History - Event-based Programming 
 Pillar of interactive UI design 
 Pillar of multi-tasking ability in operating systems (e.g. Windows Message 
Pump) 
 Familiar programming model when dealing with System.Windows.Forms
Observable Databinding 
 Based on Event-driven programming 
 Bind object instance to UI controls 
 Provides instant update of object properties 
 Through implementation of INotifyPropertyChanged (in Windows.Forms), 
can achieve two-way databinding 
 [Demo]
Mama Said Knock Me Out(js)! 
 What is KnockoutJS? 
 A library that enables two-way databinding with HTML elements 
 Provides observable behavior to otherwise POJO’s 
 Generates HTML for lists and arrays 
 Allows for binding to controls to handle events (event-based programming) 
 Is based on MVVM pattern
The Knockout(js) Punch 
 KnockoutJS also: 
 Loves it some jQuery (plays very well with jQuery) 
 Is great for plugging in on one (or a few) page(s) within a server-side app 
(ASP.NET, ASP.NET MVC with Razor, etc.) 
 Has plugins that make it easy to go from JSON POJO to observable models 
 [Demo]
What is AngularJS? 
 A Javascript (client-side) library that allows you to build web applications and single-page 
applications using the MVW design pattern 
 MVW – Model, View, Whatever! 
 Angular started as an MVC library 
 Angular has morphed to be more flexible, supporting MVVM now as well. Hence MV* 
 Angular does with HTML what HTML was never designed to do: support dynamic documents 
 Provides two-way databinding between your model and your view 
 With POJO’s! (no observable models necessary)
What AngularJS is Not 
 Difficult to learn 
 Unawesome (for the double-negative win) (ngHaha) 
 Another jQuery Library 
 To be used with jQuery 
 Angular has its own implementation of jQuery called ‘jq-lite’ 
 While Angular will play nicely with jQuery(even replacing jq-lite with it automatically), jQuery 
has a different mindset (i.e. “thinking in Angular” versus “thinking in jQuery”) 
 A jQuery developer might say: “what selector do I use to manipulate the DOM here?” 
 An AngularJS developer might say: “what business problem am I trying to solve, and is what I’m 
building now achieving good separation of concerns?” 
 Great SO Post about this: http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs- 
if-i-have-a-jquery-background
MVC Pattern in Angular 
 Model – the POJO/JSON you receive. Angular provides the ability to take this data and plug it 
right into views in an observable/databound fashion (sweeeet) 
 View – the HTML markup: 
 View templates (when using routing and SPA approach) 
 Directives that aid in manipulating (or directly manipulate) the DOM 
 Controller – functions (objects for OO developers) that provide functionality for the application 
 Things that manipulate scope 
 Things that perform business logic 
 Things that make you go hmm 
 But never, ever ever things that manipulate the DOM or any kind of UI element! 
 Because, SoC!
Now to Dig In to Angular!
The Model 
 Any kind of regular JSON or POJO! 
 $scope.person = { 
 name: 'Carlos', 
 IsCool: true, 
 hasTopLevelSecurityClearance: true 
 }; 
 Can be bound to any UI element 
 <input type=‘text’ ng-model=‘person.name’/> 
 <input type=‘check’ ng-model=‘person.IsCool’/>
The View – no Barbara Walters (sacrilege!) 
 Just a basic HTML page! 
 Views are comprised of the base HTML page (the one containing the <body> tag) 
and zero or more HTML snippets 
 HTML snippets are used when building a SPA app with the ngRoute plugin 
 In order to “turn on” (initialize) Angular, you add an ngModule attribute to the 
target element, usually body: 
 HTML: <body ng-module=“myModule> 
 JS: angular.module(‘myModule’, []); //the square brackets can list dependencies
The Controller – Pulling it All Together 
 With ngController, attaches a controller class to the view. 
 Key aspect of how angular supports the principles behind the Model-View- 
Controller 
 Contains main bit of business logic used to implement functionality 
 Use controllers to: 
 Set up the initial state of the $scope object 
 For example, loading a Person and attaching them to scope for later databinding: 
 $scope.person = myService.load(); 
 Add behavior to the $scope object 
 $scope.add = function(a, b){return a + b;}
The Controller – Part Deux 
 Controller functionality must be limited (Single Responsibility Principle) 
 In general, a Controller shouldn't try to do too much. It should contain only 
the business logic needed for a single view. 
 This is accomplished through Delegation (a core tenet of SRP) and 
dependency injection (Angular loves it some DI!!) 
 Controllers are designed to be testable, so keep testing in mind (e.g. by 
being strict about delegation and DI)
The Controller – Should Never 
 Manipulate the DOM 
 Cannot stress this enough – this will led to massive amounts of spaghetti code 
that is very hard to test and debug. Any guess on how this should be done? 
 Call external services directly 
 Use services and delegate! 
 Do more than it should 
 If building a Person entry form, should there be functionality in the controller to 
copy files? 
 Any other “Should Nevers” I missed? Don’t be shy!
Controller Sample 
 HTML: 
 <div ng-controller=“myController”> 
 <span>{{greeting}}</span> (could also do <span ng-model=“greeting”></span> 
 <button type=“button” ng-click=“showAlert()”>Show Alert</button> 
 </div> 
 angular.module(‘myModule’).controller(‘myController’, function($scope){ 
 $scope.greeting = ‘hi!’; 
 $scope.showAlert = function(){ 
 alert($scope.greetin); 
 } 
 });
That’s the End? No! 
 Brief discussion of: 
 Services 
 Factories 
 Services versus Factories (you’ll see why later, kinda odd 
naming) 
 Directives 
 If we have time: ng-route!!!
The Service 
 Generally speaking, are used to encapsulate consuming external services 
 The proper place for use of $http 
 Are DI’ed for dependencies (e.g. $http) and are also DI’ed into your 
controller 
 Can be used for communication between controllers 
 Are singletons (whereas I’m a simpleton #lol #ngRhyme)
Service Example 
 angular.module(‘myModule’).service(‘myService’, function($http){ 
 var self = this; 
 self.getPeople = function(){ 
 return $http.get(‘/theUrl’); //Any guess what this returns? 
 }; 
 }); 
 A promise! 
 Controller: 
 Angular.module(‘myModule’).controller(‘myController’, function(myService){ 
 myService.getPeople.success(function(data){ 
 //do stuff 
 }); 
 });
The Factory 
 Factories are basically services! 
 Some key differences which we’ll discuss in shortly
Factory Example 
 angular.module(‘myModule’).factory(‘myFactory’, function($http){ 
 var factory = {}; 
 factory.getPeople = function(){ 
 return $http.get(‘/theUrl’); //Any guess what this returns? 
 }; 
 return factory; 
 }); 
 A promise! 
 Controller: 
 Angular.module(‘myModule’).controller(‘myController’, function(myService){ 
 myService.getPeople.success(function(data){ 
 //do stuff 
 }); 
 });
Services vs Factories: ngTruth 
 Services are essentially Factories, however: 
Services return a new (singleton) instance of your 
Service declaration 
For example: return new myservice() 
Factories return the result of your Factory declaration 
(i.e. the return value of the Factory function) 
For example: return myService()
The (prime) Directive 
 Directives are a markers placed on DOM elements to tell Angular to 
attach special behavior to that DOM element or even transform that 
DOM element and its children 
 Directives are new syntax for HTML, and it teaches HTML new tricks 
 Angular actually works via directives! 
 ng-module (<body ng-module=“myModule”>) 
 ng-controller (<div ng-controller=“myController”>) 
 ng-click (<button type=“button” ng-click=“doTheThing()”>) 
 The only right way to manipulate the DOM with Angular
Datepicker: jQuery versus Angular 
 <input id=“date” type=“text”/> 
 jQuery: $(“date”).datepicker() 
Angular: 
<input type=“text” date-picker/> 
<date-picker></date-picker>
Directive Example 
 angular.module(‘myModule’).directive(‘helloWorld’, function(){ 
 return { 
 restrict: ‘AE’, 
 replace: ‘true’, 
 template: ‘<h3>Hello, world!</h3>’ 
 } 
 }); 
 <hello-world/> or <span hello-world></span>
Why Use Directives? 
 Great way to create reusable UI components (such as 
datepickers) 
 Great (proper) way to manipulate the DOM 
 Many built-in directives provide great levels of 
functionality, but there are times when UI behavior is 
needed that can’t be built with the included directives
ngRepeat – Directive for Collections 
 var m = [ 
 "India", 
 "England", 
 "Brazil" 
 ]; 
 function MyCtrl($scope) { 
 $scope.items = m; 
 } 
 <div ng-app ng-controller="MyCtrl"> 
 <ul> 
 <li ng-repeat=“item in items">{{item}}</li> 
 </ul> 
 </div>
Brief Demo
Time Check! 
 Route Time?
First – Single Page Apps 
 Do you prefer native Windows apps to web apps? 
 Do you prefer native mobile apps to mobile web sites? 
 The goal of Single Page Apps is to deliver an experience that looks and feels like 
a native app 
 Data is loaded in one call for most of the pages that the user will interact with, or 
is loaded dynamically as the user moves through the page using AJAX requests 
 The page is designed to look like the user is browsing through the app, but 
responds instantly and quickly and fluidly moves through to the next page in the 
site 
 No more clicking links and waiting for the page to load. That experience stinks anyway! 
 Single page apps deliver a user experience that is unmatched by classic round-trip 
based web applications
KnockoutJS for SPAs 
 Yes, KnockoutJS can be used to build a SPA! 
 However, it’s a “BYOS” situation – bring your own SPA 
 Knockout only brings observables to the table (which is pretty huge) 
 But you must bring your own: 
 Hashes (we’ll learn more about this in a minute) 
 Routing 
 Controllers 
 Server calls
ngRoute – the ng approach to SPA 
 ngRoute is an Angular plugin that provides site browsing using a classic 
URL hashing approach 
 Classic URL: http://mysite.com/people/addresses.aspx?personID=1 
 ngRoute/Hashing: http://mysite.com/people.cshtml?personID=1#addresses 
 Hashes are tied to Angular view templates 
 #addresses loads the Address view (e.g. addresses.html) which contains an 
HTML snippet for the view 
 View templates have controllers associated with them 
 View templates can be role-based and have full permissions
ngView 
 ngRoute is used in conjunction with ngView 
 <div ng-view> 
 Elements containing ngView are replaced by the view template loaded 
by ngRoute
ngRoute Example 
 angular.module(‘myModule’, [‘ngRoute’]) 
 .config(function($routeProvider){ 
 $routeProvider.when(‘/addresses’, { 
 templateUrl: ‘addresses.html’, 
 controller: ‘addressesController’ 
 }); 
 }); 
 when ‘mysite.com/main.html#addresses’ then show that view
Final Notes on AngularJS 
 AngularJS is great for building rich applications that run in a browser 
 The closer you get to SPA architecture, the more you should use AngularJS 
 And the better AngularJS will perform 
 jQuery is a fantastic tool, but does not grow well with large web apps, and 
does not lend itself to good test coverage via unit testing 
 When building a round-trip centric app, favor a combination of jQuery 
and KnockoutJS with limited Razor 
 When building a SPA, favor AngularJS. It has more up front time than 
jQuery and Knockout, but the payoff will be well worth it
The Slide Deck Is Done, Maaaaan 
 We discussed: 
 KnockoutJS and how it supports two-way databinding 
 AngularJS in depth: 
 Controllers 
 Views 
 Models 
 Directives 
 Services 
 Routes
Questions? 
 Ask ‘em if you got ‘em

More Related Content

What's hot

AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day WorkshopShyam Seshadri
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introductionLuigi De Russis
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners WorkshopSathish VJ
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation Phan Tuan
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS introdizabl
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)Gary Arora
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developersKai Koenig
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS BasicsRavi Mone
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJSWei Ru
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular jsAayush Shrestha
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBApaichon Punopas
 
Gettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSGettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSArmin Vieweg
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish MinutesDan Wahlin
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework Sakthi Bro
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.jsJosh Staples
 

What's hot (20)

AngularJS One Day Workshop
AngularJS One Day WorkshopAngularJS One Day Workshop
AngularJS One Day Workshop
 
AngularJs
AngularJsAngularJs
AngularJs
 
AngularJS: an introduction
AngularJS: an introductionAngularJS: an introduction
AngularJS: an introduction
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
 
AngularJs presentation
AngularJs presentation AngularJs presentation
AngularJs presentation
 
Angularjs Basics
Angularjs BasicsAngularjs Basics
Angularjs Basics
 
AngularJS intro
AngularJS introAngularJS intro
AngularJS intro
 
AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)AngularJS - What is it & Why is it awesome ? (with demos)
AngularJS - What is it & Why is it awesome ? (with demos)
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Angular js PPT
Angular js PPTAngular js PPT
Angular js PPT
 
AngularJS Basics
AngularJS BasicsAngularJS Basics
AngularJS Basics
 
Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
Understanding angular js
Understanding angular jsUnderstanding angular js
Understanding angular js
 
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDBDynamic Application Development by NodeJS ,AngularJS with OrientDB
Dynamic Application Development by NodeJS ,AngularJS with OrientDB
 
AngularJS Best Practices
AngularJS Best PracticesAngularJS Best Practices
AngularJS Best Practices
 
Gettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJSGettings started with the superheroic JavaScript library AngularJS
Gettings started with the superheroic JavaScript library AngularJS
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
Why angular js Framework
Why angular js Framework Why angular js Framework
Why angular js Framework
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.js
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 

Similar to Intro to AngularJs

Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersOswald Campesato
 
Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day trainingTroy Miles
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development GuideNitin Giri
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basicsRavindra K
 
One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJSYashobanta Bai
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJSAnass90
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to conceptsAbhishek Sur
 
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
 
Integrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMSIntegrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMSTom Borger
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseEPAM Systems
 
Yeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsclimboid
 
AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)Abhishek Anand
 

Similar to Intro to AngularJs (20)

Training On Angular Js
Training On Angular JsTraining On Angular Js
Training On Angular Js
 
Angular - Beginner
Angular - BeginnerAngular - Beginner
Angular - Beginner
 
Angular1x and Angular 2 for Beginners
Angular1x and Angular 2 for BeginnersAngular1x and Angular 2 for Beginners
Angular1x and Angular 2 for Beginners
 
SF Cordova Meetup
SF Cordova MeetupSF Cordova Meetup
SF Cordova Meetup
 
Ionic framework one day training
Ionic framework one day trainingIonic framework one day training
Ionic framework one day training
 
Angular workshop - Full Development Guide
Angular workshop - Full Development GuideAngular workshop - Full Development Guide
Angular workshop - Full Development Guide
 
introduction to Angularjs basics
introduction to Angularjs basicsintroduction to Angularjs basics
introduction to Angularjs basics
 
AngularJS Workshop
AngularJS WorkshopAngularJS Workshop
AngularJS Workshop
 
One Weekend With AngularJS
One Weekend With AngularJSOne Weekend With AngularJS
One Weekend With AngularJS
 
Introduction to AngularJS
Introduction to AngularJSIntroduction to AngularJS
Introduction to AngularJS
 
Angular JS, A dive to concepts
Angular JS, A dive to conceptsAngular JS, A dive to concepts
Angular JS, A dive to concepts
 
AngularJS 101
AngularJS 101AngularJS 101
AngularJS 101
 
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
 
Integrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMSIntegrating AngularJS into the Campus CMS
Integrating AngularJS into the Campus CMS
 
Angular Js Get Started - Complete Course
Angular Js Get Started - Complete CourseAngular Js Get Started - Complete Course
Angular Js Get Started - Complete Course
 
Yeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web apps
 
AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)AngularJS Introduction (Talk given on Aug 5 2013)
AngularJS Introduction (Talk given on Aug 5 2013)
 
Angular js
Angular jsAngular js
Angular js
 
Angular js workshop
Angular js workshopAngular js workshop
Angular js workshop
 
Directives
DirectivesDirectives
Directives
 

More from SolTech, Inc.

Responsive Web Design using the Foundation 5 CSS Framework
Responsive Web Design using the Foundation 5 CSS FrameworkResponsive Web Design using the Foundation 5 CSS Framework
Responsive Web Design using the Foundation 5 CSS FrameworkSolTech, Inc.
 
How to Rock your Phone Interview: 4 Easy Steps
How to Rock your Phone Interview: 4 Easy StepsHow to Rock your Phone Interview: 4 Easy Steps
How to Rock your Phone Interview: 4 Easy StepsSolTech, Inc.
 
Empowering Your Job Search: 10 Tips
Empowering Your Job Search: 10 TipsEmpowering Your Job Search: 10 Tips
Empowering Your Job Search: 10 TipsSolTech, Inc.
 
Responsive Web Design using ZURB Foundation
Responsive Web Design using ZURB FoundationResponsive Web Design using ZURB Foundation
Responsive Web Design using ZURB FoundationSolTech, Inc.
 
Introduction to Dependency Injection
Introduction to Dependency InjectionIntroduction to Dependency Injection
Introduction to Dependency InjectionSolTech, Inc.
 
Getting started with Xamarin forms
Getting started with Xamarin formsGetting started with Xamarin forms
Getting started with Xamarin formsSolTech, Inc.
 
Debugging Javascript
Debugging JavascriptDebugging Javascript
Debugging JavascriptSolTech, Inc.
 
SolTech's The Constantly Connected Customer
SolTech's The Constantly Connected CustomerSolTech's The Constantly Connected Customer
SolTech's The Constantly Connected CustomerSolTech, Inc.
 

More from SolTech, Inc. (8)

Responsive Web Design using the Foundation 5 CSS Framework
Responsive Web Design using the Foundation 5 CSS FrameworkResponsive Web Design using the Foundation 5 CSS Framework
Responsive Web Design using the Foundation 5 CSS Framework
 
How to Rock your Phone Interview: 4 Easy Steps
How to Rock your Phone Interview: 4 Easy StepsHow to Rock your Phone Interview: 4 Easy Steps
How to Rock your Phone Interview: 4 Easy Steps
 
Empowering Your Job Search: 10 Tips
Empowering Your Job Search: 10 TipsEmpowering Your Job Search: 10 Tips
Empowering Your Job Search: 10 Tips
 
Responsive Web Design using ZURB Foundation
Responsive Web Design using ZURB FoundationResponsive Web Design using ZURB Foundation
Responsive Web Design using ZURB Foundation
 
Introduction to Dependency Injection
Introduction to Dependency InjectionIntroduction to Dependency Injection
Introduction to Dependency Injection
 
Getting started with Xamarin forms
Getting started with Xamarin formsGetting started with Xamarin forms
Getting started with Xamarin forms
 
Debugging Javascript
Debugging JavascriptDebugging Javascript
Debugging Javascript
 
SolTech's The Constantly Connected Customer
SolTech's The Constantly Connected CustomerSolTech's The Constantly Connected Customer
SolTech's The Constantly Connected Customer
 

Recently uploaded

办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commercemanigoyal112
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 

Recently uploaded (20)

办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Cyber security and its impact on E commerce
Cyber security and its impact on E commerceCyber security and its impact on E commerce
Cyber security and its impact on E commerce
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 

Intro to AngularJs

  • 1. Intro to AngularJS ANGULAR BY WAY OF KNOCKOUTJS AND OBSERVABLE PROGRAMMING
  • 2. ngAgenda  Brief History on Observable Programming  Brief introduction to observable Javascript using KnockoutJS  Single Page App (SPA) Architecture  Comparison to roundtrip-based app  High-level Overview of AngularJS Fundamentals  Introduction to MVC in AngularJS  1 Rule: Please don’t debate my slides or demos! Save it for the after party =D  But I love questions!  Embrace “ng” – everything in the Angular world is preceded by “ng”  Oh, and find the error for a prize! Call them out as you see them 
  • 3. Brief History - Event-based Programming  Pillar of interactive UI design  Pillar of multi-tasking ability in operating systems (e.g. Windows Message Pump)  Familiar programming model when dealing with System.Windows.Forms
  • 4. Observable Databinding  Based on Event-driven programming  Bind object instance to UI controls  Provides instant update of object properties  Through implementation of INotifyPropertyChanged (in Windows.Forms), can achieve two-way databinding  [Demo]
  • 5. Mama Said Knock Me Out(js)!  What is KnockoutJS?  A library that enables two-way databinding with HTML elements  Provides observable behavior to otherwise POJO’s  Generates HTML for lists and arrays  Allows for binding to controls to handle events (event-based programming)  Is based on MVVM pattern
  • 6. The Knockout(js) Punch  KnockoutJS also:  Loves it some jQuery (plays very well with jQuery)  Is great for plugging in on one (or a few) page(s) within a server-side app (ASP.NET, ASP.NET MVC with Razor, etc.)  Has plugins that make it easy to go from JSON POJO to observable models  [Demo]
  • 7. What is AngularJS?  A Javascript (client-side) library that allows you to build web applications and single-page applications using the MVW design pattern  MVW – Model, View, Whatever!  Angular started as an MVC library  Angular has morphed to be more flexible, supporting MVVM now as well. Hence MV*  Angular does with HTML what HTML was never designed to do: support dynamic documents  Provides two-way databinding between your model and your view  With POJO’s! (no observable models necessary)
  • 8. What AngularJS is Not  Difficult to learn  Unawesome (for the double-negative win) (ngHaha)  Another jQuery Library  To be used with jQuery  Angular has its own implementation of jQuery called ‘jq-lite’  While Angular will play nicely with jQuery(even replacing jq-lite with it automatically), jQuery has a different mindset (i.e. “thinking in Angular” versus “thinking in jQuery”)  A jQuery developer might say: “what selector do I use to manipulate the DOM here?”  An AngularJS developer might say: “what business problem am I trying to solve, and is what I’m building now achieving good separation of concerns?”  Great SO Post about this: http://stackoverflow.com/questions/14994391/how-do-i-think-in-angularjs- if-i-have-a-jquery-background
  • 9. MVC Pattern in Angular  Model – the POJO/JSON you receive. Angular provides the ability to take this data and plug it right into views in an observable/databound fashion (sweeeet)  View – the HTML markup:  View templates (when using routing and SPA approach)  Directives that aid in manipulating (or directly manipulate) the DOM  Controller – functions (objects for OO developers) that provide functionality for the application  Things that manipulate scope  Things that perform business logic  Things that make you go hmm  But never, ever ever things that manipulate the DOM or any kind of UI element!  Because, SoC!
  • 10. Now to Dig In to Angular!
  • 11. The Model  Any kind of regular JSON or POJO!  $scope.person = {  name: 'Carlos',  IsCool: true,  hasTopLevelSecurityClearance: true  };  Can be bound to any UI element  <input type=‘text’ ng-model=‘person.name’/>  <input type=‘check’ ng-model=‘person.IsCool’/>
  • 12. The View – no Barbara Walters (sacrilege!)  Just a basic HTML page!  Views are comprised of the base HTML page (the one containing the <body> tag) and zero or more HTML snippets  HTML snippets are used when building a SPA app with the ngRoute plugin  In order to “turn on” (initialize) Angular, you add an ngModule attribute to the target element, usually body:  HTML: <body ng-module=“myModule>  JS: angular.module(‘myModule’, []); //the square brackets can list dependencies
  • 13. The Controller – Pulling it All Together  With ngController, attaches a controller class to the view.  Key aspect of how angular supports the principles behind the Model-View- Controller  Contains main bit of business logic used to implement functionality  Use controllers to:  Set up the initial state of the $scope object  For example, loading a Person and attaching them to scope for later databinding:  $scope.person = myService.load();  Add behavior to the $scope object  $scope.add = function(a, b){return a + b;}
  • 14. The Controller – Part Deux  Controller functionality must be limited (Single Responsibility Principle)  In general, a Controller shouldn't try to do too much. It should contain only the business logic needed for a single view.  This is accomplished through Delegation (a core tenet of SRP) and dependency injection (Angular loves it some DI!!)  Controllers are designed to be testable, so keep testing in mind (e.g. by being strict about delegation and DI)
  • 15. The Controller – Should Never  Manipulate the DOM  Cannot stress this enough – this will led to massive amounts of spaghetti code that is very hard to test and debug. Any guess on how this should be done?  Call external services directly  Use services and delegate!  Do more than it should  If building a Person entry form, should there be functionality in the controller to copy files?  Any other “Should Nevers” I missed? Don’t be shy!
  • 16. Controller Sample  HTML:  <div ng-controller=“myController”>  <span>{{greeting}}</span> (could also do <span ng-model=“greeting”></span>  <button type=“button” ng-click=“showAlert()”>Show Alert</button>  </div>  angular.module(‘myModule’).controller(‘myController’, function($scope){  $scope.greeting = ‘hi!’;  $scope.showAlert = function(){  alert($scope.greetin);  }  });
  • 17. That’s the End? No!  Brief discussion of:  Services  Factories  Services versus Factories (you’ll see why later, kinda odd naming)  Directives  If we have time: ng-route!!!
  • 18. The Service  Generally speaking, are used to encapsulate consuming external services  The proper place for use of $http  Are DI’ed for dependencies (e.g. $http) and are also DI’ed into your controller  Can be used for communication between controllers  Are singletons (whereas I’m a simpleton #lol #ngRhyme)
  • 19. Service Example  angular.module(‘myModule’).service(‘myService’, function($http){  var self = this;  self.getPeople = function(){  return $http.get(‘/theUrl’); //Any guess what this returns?  };  });  A promise!  Controller:  Angular.module(‘myModule’).controller(‘myController’, function(myService){  myService.getPeople.success(function(data){  //do stuff  });  });
  • 20. The Factory  Factories are basically services!  Some key differences which we’ll discuss in shortly
  • 21. Factory Example  angular.module(‘myModule’).factory(‘myFactory’, function($http){  var factory = {};  factory.getPeople = function(){  return $http.get(‘/theUrl’); //Any guess what this returns?  };  return factory;  });  A promise!  Controller:  Angular.module(‘myModule’).controller(‘myController’, function(myService){  myService.getPeople.success(function(data){  //do stuff  });  });
  • 22. Services vs Factories: ngTruth  Services are essentially Factories, however: Services return a new (singleton) instance of your Service declaration For example: return new myservice() Factories return the result of your Factory declaration (i.e. the return value of the Factory function) For example: return myService()
  • 23. The (prime) Directive  Directives are a markers placed on DOM elements to tell Angular to attach special behavior to that DOM element or even transform that DOM element and its children  Directives are new syntax for HTML, and it teaches HTML new tricks  Angular actually works via directives!  ng-module (<body ng-module=“myModule”>)  ng-controller (<div ng-controller=“myController”>)  ng-click (<button type=“button” ng-click=“doTheThing()”>)  The only right way to manipulate the DOM with Angular
  • 24. Datepicker: jQuery versus Angular  <input id=“date” type=“text”/>  jQuery: $(“date”).datepicker() Angular: <input type=“text” date-picker/> <date-picker></date-picker>
  • 25. Directive Example  angular.module(‘myModule’).directive(‘helloWorld’, function(){  return {  restrict: ‘AE’,  replace: ‘true’,  template: ‘<h3>Hello, world!</h3>’  }  });  <hello-world/> or <span hello-world></span>
  • 26. Why Use Directives?  Great way to create reusable UI components (such as datepickers)  Great (proper) way to manipulate the DOM  Many built-in directives provide great levels of functionality, but there are times when UI behavior is needed that can’t be built with the included directives
  • 27. ngRepeat – Directive for Collections  var m = [  "India",  "England",  "Brazil"  ];  function MyCtrl($scope) {  $scope.items = m;  }  <div ng-app ng-controller="MyCtrl">  <ul>  <li ng-repeat=“item in items">{{item}}</li>  </ul>  </div>
  • 29. Time Check!  Route Time?
  • 30. First – Single Page Apps  Do you prefer native Windows apps to web apps?  Do you prefer native mobile apps to mobile web sites?  The goal of Single Page Apps is to deliver an experience that looks and feels like a native app  Data is loaded in one call for most of the pages that the user will interact with, or is loaded dynamically as the user moves through the page using AJAX requests  The page is designed to look like the user is browsing through the app, but responds instantly and quickly and fluidly moves through to the next page in the site  No more clicking links and waiting for the page to load. That experience stinks anyway!  Single page apps deliver a user experience that is unmatched by classic round-trip based web applications
  • 31. KnockoutJS for SPAs  Yes, KnockoutJS can be used to build a SPA!  However, it’s a “BYOS” situation – bring your own SPA  Knockout only brings observables to the table (which is pretty huge)  But you must bring your own:  Hashes (we’ll learn more about this in a minute)  Routing  Controllers  Server calls
  • 32. ngRoute – the ng approach to SPA  ngRoute is an Angular plugin that provides site browsing using a classic URL hashing approach  Classic URL: http://mysite.com/people/addresses.aspx?personID=1  ngRoute/Hashing: http://mysite.com/people.cshtml?personID=1#addresses  Hashes are tied to Angular view templates  #addresses loads the Address view (e.g. addresses.html) which contains an HTML snippet for the view  View templates have controllers associated with them  View templates can be role-based and have full permissions
  • 33. ngView  ngRoute is used in conjunction with ngView  <div ng-view>  Elements containing ngView are replaced by the view template loaded by ngRoute
  • 34. ngRoute Example  angular.module(‘myModule’, [‘ngRoute’])  .config(function($routeProvider){  $routeProvider.when(‘/addresses’, {  templateUrl: ‘addresses.html’,  controller: ‘addressesController’  });  });  when ‘mysite.com/main.html#addresses’ then show that view
  • 35. Final Notes on AngularJS  AngularJS is great for building rich applications that run in a browser  The closer you get to SPA architecture, the more you should use AngularJS  And the better AngularJS will perform  jQuery is a fantastic tool, but does not grow well with large web apps, and does not lend itself to good test coverage via unit testing  When building a round-trip centric app, favor a combination of jQuery and KnockoutJS with limited Razor  When building a SPA, favor AngularJS. It has more up front time than jQuery and Knockout, but the payoff will be well worth it
  • 36. The Slide Deck Is Done, Maaaaan  We discussed:  KnockoutJS and how it supports two-way databinding  AngularJS in depth:  Controllers  Views  Models  Directives  Services  Routes
  • 37. Questions?  Ask ‘em if you got ‘em