© Luxoft Training. All rights reserved AngularJS Introduction.

Slides:



Advertisements
Similar presentations
Introducing JavaScript
Advertisements

JavaScript and AJAX Jonathan Foss University of Warwick
JavaScript FaaDoOEngineers.com FaaDoOEngineers.com.
Validation in Angular 1.3 And other angular tidbits.
JavaScript Part for Repetition Statement for statement Cpecifies each of the items needed for counter-controlled repetition with a control variable.
Javascript and AJAX Willem Visser RW334. Overview Javascript jQuery AngularJS AJAX.
DT228/3 Web Development JSP: Directives and Scripting elements.
Dynamic Web Pages Bert Wachsmuth. Review  Internet, IP addresses, ports, client-server, http, smtp  HTML, XHTML, XML  Style Sheets, external, internal,
Using Spring 4 and AngularJS for REST-based web applications development Vladimir Sonkin Java & Web expert Luxoft Training.
Development of mobile applications using PhoneGap and HTML 5
Single Page Applications with AngluarJS Bill Wolff Rob Keiser
SUNY Polytechnic Institute CS 490 – Web Design, AJAX, jQueryAngularJS AngularJS is a client-side JavaScript Framework for adding interactivity to HTML.
Introduction Marko Marić, Danulabs
Philly.NET Hands-on Labs JAVASCRIPT SERIES. July 9: JavaScript Syntax Visual Studio ◦Projects ◦Editors ◦Debugging ◦Script blocks ◦Minification and bundling.
CIS 375—Web App Dev II ASP.NET 2 Introducing Web Forms.
JQuery Adding behaviour…. Lecture Plan Review of last lesson Adding behaviour –click, mouseover Animation –fade, slideDown Navigation –parent, find, next.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
AngularJS Directives Defining Custom Directives SoftUni Team Technical Trainers Software University
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Introduction to Angular JS Sergey Barskiy Working Class Nobody Level: Introductory.
ANGULARJS A Gentle Introduction John /
JavaScript Scripting language What is Scripting ? A scripting language, script language, or extension language is a programming language.
Controllers and Markup Controllers, $scope, Markup, Directives, Expressions, Binding, Filters, Validation SoftUni Team Technical Trainers Software University.
Introduction to Angular James Kahng. Terms Framework Template/environment constructed in the language where you fill in details with code Library Set.
Canopy walk through Single-Page Apps (SPAs) Benjamin Howarth Freelancer, Code Gecko Umbraco UK Festival, Fri 30 th Oct 2015 CODE GECKO.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 JSP Application Models.
Angular Gotchas Best of Web…but watch out Responsive application build with HTML5 and Javascript Mike R. Emo Founder iEmoSoft consulting Featuring Nick.
Getting Started with Aurelia
ANGULARJS A Gentle Introduction John Madison.NET User Group.
10 Copyright © 2004, Oracle. All rights reserved. Building ADF View Components.
Chapter 1 Ionic Framework (overview) Front-end framework for developing hybrid mobile apps with HTML5 Yeunyong Kantanet School of Information and Communication.
Flux & React Web Application Development Mark Repka, Rich McNeary, Steve Mueller.
Martin Kruliš by Martin Kruliš (v1.0)1.
AngularJS. What is AngularJS  Javascript Framework  MVC  for Rich Web Application Development  by Google.
AngularJS and SharePoint
Vineel Vutukuri. What is SPA? Why SPA? Pros & Cons When to use SPA?
Chapter 5 Angularjs. Content Overview How to program with Angularjs Directives Expressions Controllers Filters HTML DOM Forms and Includes Ajax Scopes.
JavaScript Basics Stephen Delaney
DHTML.
Angular JS and SharePoint
Web Programming Anselm Spoerri PhD (MIT) Rutgers University
Web Technologies Computing Science Thompson Rivers University
Extra Course
Javascript and AJAX Willem Visser RW334.
CMPE 280 Web UI Design and Development October 26 Class Meeting
AngularJS A Gentle Introduction John
JavaScript Basics Stephen Delaney
PHP Training at GoLogica in Bangalore
CMPE 280 Web UI Design and Development November 7 Class Meeting
Jessica Betts, Sophia Pandey, & Ryan Amundson
Angularjs Interview Questions and Answers By Hope Tutors.
Design and Maintenance of Web Applications in J2EE
MEAN stack L. Grewe.
Step by Step - AngularJS
Angular (JS): A Framework for Dynamic Web Pages
jQuery The Easy JavaScript Nikolay Chochev Technical Trainer
Building responsive apps and sites with HTML5 web workers
15 minute break.
Secure Web Programming
AngularJS Michael Kang August 20th 2015.
Chengyu Sun California State University, Los Angeles
Javascript Chapter 19 and 20 5/3/2019.
Chengyu Sun California State University, Los Angeles
PART 1.
Web Technologies Computing Science Thompson Rivers University
Web Client Side Technologies Raneem Qaddoura
Web Programming and Design
CMPE 280 Web UI Design and Development November 8 Class Meeting
Presentation transcript:

© Luxoft Training. All rights reserved AngularJS Introduction

© Luxoft Training. All rights reserved Why to use HTML5 frameworks Dealwithcross-browser compatibility Makeyourapplicationmorestructured Mayincludereusablecomponents Makeprogrammersmoreproductive Lowertheamountofmanuallywrittencode

© Luxoft Training. All rights reserved Frameworks and Libraries Frameworks expect you to develop using well defined rules. Libraries just offer reusable components There are two major types of frameworks: Feature complete frameworks Lightweight frameworks (MVC + Binding + Routing)

Feature Complete Frameworks Suitable for back-office applications Include a library of UI components Have good tooling Steeper learning curve May be difficult to customize The size of the app 1MB+

Lightweight Frameworks Work best for consumer-oriented websites Can be combined with 3-party libraries Easier to learn Mainly deal with application structure, navigation, AJAX

HTML enhanced for web apps! Here comes… AngularJS

Why AngularJS? Goodchoiceforsingle-pageapplications MVCwithminimalcoding Easyrouting Lightweight,yetpluggablewithwell-definedmodular architecture FollowsmodernWebstandards

© Luxoft Training. All rights reserved Architecture Templating UI widgets/components Avoids DOM manipulation testing modularity, loose coupling and reusability What AngularJS provides?

© Luxoft Training. All rights reserved

© Luxoft Training. All rights reserved Two way data binding example MODEL $scope.name="John“; John Smith Name: ng-model="name" VIEW MODEL $scope.name=="John Smith"; John Name: ng-model="name" VIEW

© Luxoft Training. All rights reserved Scope A scope shares variables between view and controller A scope is a place where the model data are located

Data binding

© Luxoft Training. All rights reserved

© Luxoft Training. All rights reserved Why use a JS MVC framework Poor distribution of processing – With a large number of clients, doing all the processing on the server is inefficient. High user response latency Difficult programming model Increased vector of attack Heavy state management on the servers Offline Difficulties Reduced opportunity for interoperability

© Luxoft Training. All rights reserved Why use a JS MVC framework Scalability - The more clients that use an application, the more client machines that are available, whereas the server processing capabilities remain constant Immediate user response Organized programming model Client side state management Offline applications Interoperability JSMVC Web Applications

© Luxoft Training. All rights reserved Client/server architecture for modern web applications Fullstack JS frameworks contain a mix of the following components: A client side JS framework like Angular/Backbone/Require or other NodeJS as backend application server MongoDB or other document databases based on JS model

© Luxoft Training. All rights reserved Data Flow for modern web development

© Luxoft Training. All rights reserved AngularJS interest: stackoverflow questions

© Luxoft Training. All rights reserved AngularJS interest

Single-Page Application (SPA) No full Web page reloads Only certain pages get refreshed as results of AJAX calls Parts of the page may toggle from visible to hidden using CSS The Web page states doesn’t get reset The user gets a feel of a desktop app The SEO may suffer, need special tricks

Professional SPA features Modularization ControllershandlesDOMmanipulationsandAJAX HTMLtemplating Routingwithdeeplinking RealtimecommunicationviaWebsockets UseofHTML5Localstorage

Hello {{helloTo.title}} ! angular.module("myapp", []).controller("HelloController", function($scope) { $scope.helloTo = {}; $scope.helloTo.title = "World, AngularJS"; } ); Hello World

© Luxoft Training. All rights reserved Scope hierarchy

{{data.theVar}} {{data.theVar}} var module = angular.module("myapp", []); var myController1 = module.controller("myController1", function($scope) { $scope.data = { theVar : "Value One"}; }); var myController2 = module.controller("myController2", function($scope) { $scope.data = { theVar : "Value Two"}; }); $scope Hierarchy

© Luxoft Training. All rights reserved $watch() function $watch() enables to set a callback function to be called whenever the value of a given expression changes: $scope.$watch("name", function(newValue, oldValue) { if ($scope.name.length > 0) { $scope.greeting = "Greetings, " + $scope.name; } }); Template: {{greeting}} In this (simple) case it can be done easier: Template: Greetings, {{name}}

© Luxoft Training. All rights reserved $watch() function More complicated case: $scope.$watch('name', function(value) { var firstSpace = (value || "").indexOf(' '); if (firstSpace == -1) { $scope.firstName = value; $scope.lastName = ""; } else { $scope.firstName = value.substr(0, firstSpace); $scope.lastName = value.substr(firstSpace + 1); } });

…using $scope.$watch()

$digest() cycle $digest evaluates all the $watch expressions in a scope, as well as the scope’s children, and fires the watcher callback on any that have changed

Digest cycle

© Luxoft Training. All rights reserved $digest() var dirty = true; var iterations = 0; while (dirty && iterations++ < TIMES_TO_LOOP) { dirty = false; for (var i = 0; i < scope.watchers.length(); ++i) { var currentValue = scope.watchers[i].get(); if (currentValue != scope.watchers[i].oldValue) { dirty = true; scope.watchers[i].callback(currentValue, scope.watchers[i].oldValue); scope.watchers[i].oldValue = currentValue; } TIMES_TO_LOOP constraint exists to prevent AngularJS from getting stuck in an infinite loop in $digest. If the loop executes more than TTL times, AngularJS throws a 10 $digest iterations reached Aborting! error.

© Luxoft Training. All rights reserved $apply() function informs AngularJS that something has changed and the values of $watch expressions should be recomputed $scope.getWeather = function() { $.get(weatherUrl, function(data) { $scope.weather = data; $scope.$apply(); }); }

document.getElementById("updateTimeButton").addEventListener('click', function() { console.log("update time clicked"); $scope.data.time = new Date(); $scope.$apply(); }); document.getElementById("updateTimeButton").addEventListener('click', function() { $scope.$apply(function() { console.log("update time clicked"); $scope.data.time = new Date(); }); Custom use of $apply()

Data binding event loop ng-model ng-bind

Perfomance of two-way binding Legendary Stanford computer science professor Donald Knuth: “Premature optimization is the root of all evil" AngularJS team informally recommends that you have less than 2,000 watchers on a single page The master ‐ detail pattern usually displays static information in the master list. Suppose your application is a list of upcoming events: You don’t want people browsing events to be able to change the title of any given event! In cases like this, setting a watcher on the event title is a waste because the user should not be able to modify the title anyway.

© Luxoft Training. All rights reserved Standard directives

© Luxoft Training. All rights reserved Standard directives © 2014 Farata Systems 39 A directive is something that introduces new syntax. Directives are markers on a DOM element which attach a special behavior to it. Directives offer: ‣ UI decomposition ‣ Reusable components Examples: ng-app, ng-model

© Luxoft Training. All rights reserved Directive representation in template Can be represented in four flavors: HTML element’s attribute: ng-user HTML element: CSS class: Comment:

© Luxoft Training. All rights reserved AngularJS standard directives

{{myData.textf()}} angular.module("myapp", []).controller("MyController", function($scope) { $scope.myData = {}; $scope.myData.textf = function() { return "A text from a function"; }; }); Interpolation Directive: ng-bind or {{}}

ng-show + ng-hide Directives will be show will be hidden angular.module("myapp", []).controller("MyController", function($scope) { $scope.myData = {}; $scope.myData.showIt = true; });

ng-switch Directive Shown when switch is 1 Shown when switch is 2 Shown when switch is anything else than 1 and 2 angular.module("myapp", []).controller("MyController", function($scope) { $scope.myData = {}; $scope.myData.switch = 3; });

ng-if Directive ng-if Show it angular.module("myapp", []).controller("MyController", function($scope) { $scope.myData = {}; $scope.myData.showIt = true; });

ng-include Directive <div ng-include="myData.showIt && 'fragment-1.html' || 'fragment-2.html'"> angular.module("myapp", []).controller("MyController", function($scope) { $scope.myData = {}; $scope.myData.showIt = true; });

ng-repeat Directive {{theItem.text}} angular.module("myapp", []).controller("MyController", function($scope) { $scope.myData = {}; $scope.myData.items = [ {text : "one"}, {text : "two"}, {text : "three"} ]; }); Special ng-repeat Variables: $index - index of the element being iterated $first, $middle, $last - boolean value depending on whether the current item is the first, middle or last {{$index+1}}) {{theItem.text}}

© Luxoft Training. All rights reserved Directive classes

© Luxoft Training. All rights reserved Filtering data

Filtering angular.module("myapp", []).controller("MyController", function($scope) { $scope.myData = {}; $scope.myData.items = [ {text : "one"}, {text : "two"}, {text : "three"}, {text : "four"} ]; $scope.itemFilter = function(item) { if(item.text == "two") return false; return true; } });

Formatting Filters {{myData.theDate | date: 'dd-MM-yyyy'}} {{myData.theNumber | number: 2}} {{myData.mixedCaseText | lowercase}} {{myData.mixedCaseText | uppercase}}

Array Filters {{myData.theText | limitTo: 3}}

Filtered: {{myData.text | myFilter:2:5}} var module = angular.module("myapp", []); module.filter('myFilter', function() { return function(stringValue, startIndex, endIndex) { return stringValue.substring( parseInt(startIndex), parseInt(endIndex)); }; }); Custom Filters

© Luxoft Training. All rights reserved JavaScript events in AngularJS

AngularJS Event Listener Directives ng-click ng-dbl-click ng-mousedown ng-mouseup ng-mouseenter ng-mouseleave ng-mousemove ng-mouseover ng-keydown ng-keyup ng-keypress ng-change Click here angular.module("myapp", []).controller("MyController", function($scope) { $scope.myData = {}; $scope.myData.doClick = function() { alert("clicked"); } } );

Click here angular.module("myapp", []).controller("MyController", function($scope) { $scope.myData = {}; $scope.myData.doClick = function(event) { alert("clicked: " + event.clientX + ", " + event.clientY); } } ); Event Object passing

<li ng-repeat="item in myData.items" ng-click="myData.doClick(item, $event)">Click here angular.module("myapp", []).controller("MyController", function($scope) { $scope.myData = {}; $scope.myData.items = [{ v: "1"}, { v: "2"}, { v : "3"} ]; $scope.myData.doClick = function(item, event) { alert("clicked: " + item.v + ” + event.clientX + ": " + event.clientY); } } ); Passing parameters to event listener

© Luxoft Training. All rights reserved AngularJS modules

Controllers Handleuserinteractions Createsthemodelvariablesonthe$scopeobject Providedata-bindingsource(model)forviews Receivecontrolduringrouting Nevermanipulatetheviewdirectly Aviewcanhavemultiple controllers

Frequently used AngularJS services $scope-accesstothe current scope current $rootScope-accesstotherootscope $http-HTTPrequests $location-toworkwithwindow.location $window-toaccesswindowobject

© Luxoft Training. All rights reserved