Frontend Frameworks. SWE 432, Fall 2016 Design and Implementation of Software for the Web

Similar documents
a Very Short Introduction to AngularJS

Nagaraju Bende

Tools. SWE 432, Fall Design and Implementation of Software for the Web

Single Page Applications using AngularJS

AngularJS Fundamentals

AngularJS. Beginner's guide - part 1

Persistence & State. SWE 432, Fall 2016 Design and Implementation of Software for the Web

AngularJS AN INTRODUCTION. Introduction to the AngularJS framework

AngularJS. Beginner's guide - part 2

Simple AngularJS thanks to Best Practices

3 Days Training Program

Building mobile app using Cordova and AngularJS, common practices. Goran Kopevski

Introduction to AngularJS

Design and Implementation of Single Page Application Based on AngularJS

Getting Started with

Comprehensive AngularJS Programming (5 Days)

Tim Roes. Android- & inovex in Karlsruhe. GDG Karlsruhe Co-Organizer.

Web Application Development

Templates and Databinding. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Backend Development. SWE 432, Fall Web Application Development

,

P a g e 1. Danish Technological Institute. Scripting and Web Languages Online Course k Scripting and Web Languages

THE HITCHHIKERS GUIDE TO. Harper Maddox CTO, EdgeTheory 30 September 2014

Creating Effective Websites using AngularJS

welcome to BOILERCAMP HOW TO WEB DEV

ANGULARJS INTERVIEW QUESTIONS

Understanding Angular Directives By Jeffry Houser

One Framework. Angular

Using AngularJS In APEX. Dan McGhan Senior Technical Consultant

Model-View-Whatever A COMPARISON OF JAVASCRIPT MVC/MVP/MVVM FRAMEWORKS. J. Tower

Connecting Angular and CFML

The magic behind. Angular 2+

CodeValue. C ollege. Prerequisites: Basic knowledge of web development and especially JavaScript.

AngularJS Intro Homework

Organizing Code in Web Apps. SWE 432, Fall 2016 Design and Implementation of Software for the Web

Client Side JavaScript and AJAX

Full Stack Developer with Java

AngularJS Examples pdf

Backend Development. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Frontend guide. Everything you need to know about HTML, CSS, JavaScript and DOM. Dejan V Čančarević

Full Stack Web Developer

Introduction to. Angular. Prof. Dr.-Ing. Thomas Wiedemann.

Model-View-Control Pattern for User Interactive Systems

"Charting the Course... Comprehensive Angular. Course Summary

Financial. AngularJS. AngularJS. Download Full Version :

Treating Framework Fatigue With JavaScript

HTML DOM IN ANGULARJS

What is AngularJS. à Javascript Framework à MVC à for Rich Web Application Development à by Google

Questions and Answers from Lukas Ruebbelke s AngularJS In-Depth Course

Financial. AngularJS. AngularJS.

THE PRAGMATIC INTRO TO REACT. Clayton Anderson thebhwgroup.com WEB AND MOBILE APP DEVELOPMENT AUSTIN, TX

Ten interesting features of Google s Angular Project

Future Web App Technologies

Web Development for Dinosaurs An Introduction to Modern Web Development

Angular 2 and TypeScript Web Application Development

Frontend UI Training. Whats App :

ANGULAR2 OVERVIEW. The Big Picture. Getting Started. Modules and Components. Declarative Template Syntax. Forms

Practical Course: Web Development Angular JS Part I Winter Semester 2016/17. Juliane Franze

Front End. Presentation Layer. UI (User Interface) User <==> Data access layer

CS193X: Web Programming Fundamentals

Dynamic Web Development

ANGULAR 10. Christian Ulbrich (Zalari)

Data-Centric Single Page Apps with Angular, Web API, and Breeze

JavaScript Fundamentals_

IN4MATX 133: User Interface Software

Angular 2: What s new? Jonas Bandi, IvoryCode GmbH

ANGULAR 2.X,4.X + TYPESRCIPT by Sindhu

High Performance Single Page Application with Vue.js

Front End Programming

Angular 4 Training Course Content

Unifer Documentation. Release V1.0. Matthew S

Mobile Web Applications. Gary Dubuque IT Research Architect Department of Revenue

CSC 443: Web Programming

Web Software Model CS 4640 Programming Languages for Web Applications

Hands on Angular Framework

All India Council For Research & Training

ANGULARJS - MOCK TEST ANGULARJS MOCK TEST II

REST Easy with Infrared360

Session 3: JavaScript - Structured Programming

Angular 2 Programming

WEB DEVELOPER BLUEPRINT

DECOUPLING PATTERNS, SERVICES AND CREATING AN ENTERPRISE LEVEL EDITORIAL EXPERIENCE

Part 1: Data-Binding Frameworks (e.g. AngularJS)

Table of Contents. Introduction 1. 1 Jumping Into JavaScript 5. for Loops 17

Full Stack Web Developer

Security. SWE 432, Fall 2017 Design and Implementation of Software for the Web

AngularJS Introduction

Client Side MVC with Backbone & Rails. Tom

Welcome to CS50 section! This is Week 10 :(

NoSQL & Firebase. SWE 432, Fall Web Application Development

Modern and Responsive Mobile-enabled Web Applications

Testing & Performance. SWE 432, Fall 2016 Design and Implementation of Software for the Web

Ten good practices for ASP.NET MVC applications

Advance Mobile& Web Application development using Angular and Native Script

Angular 2 and TypeScript Web Application Development

React Not Just Hype!

Catbook Workshop 1: Client Side JS. Danny Tang

UI Course HTML: (Html, CSS, JavaScript, JQuery, Bootstrap, AngularJS) Introduction. The World Wide Web (WWW) and history of HTML

Microservices. SWE 432, Fall 2017 Design and Implementation of Software for the Web

Node.js. Node.js Overview. CS144: Web Applications

Transcription:

Frontend Frameworks SWE 432, Fall 2016 Design and Implementation of Software for the Web

Today How do we build a single page app without dying? MVC/MVVM (AngularJS) For further reading: Book: Learning Javascript Design Patterns, Osmani (Safari books online) Book: AngularJS in Action, Ruebbelke & Ford (Safari books online) Book: Learning AngularJS, Williamson (Safari books online) Only look at references for AngularJS (NOT Angular2) Demos (source/clone git): https://github.com/gmu-swe432/lecture10demos Source (run in browser): https://gmu-swe432.github.io/lecture10demos/ 2

Single Page Application Many challenges DOM Manipulation Browser events HTML HTML elements Javascript History Tracking HTTP Request HTTP Response (JSON) Caching Web Server Presentation tier Data Binding Domain logic tier Persistence tier Routing Loading Views Handling a ton of async Database 3

4

Angular to the Rescue Full-featured SPA framework (can be used for non- SPA sites too!) It s full of buzzwords! Data binding, MVC, MVVM, Routing, Testing, jqlite, Templates, History, Factories, Directives, Services, Dependency Injection, Validation, and all of their friends! There are other frameworks too, they work fine, but we re focusing on AngularJS: Aurelia Backbone.js Ember.js 5

Keeping stuff organized How do we break apart components?

My Very Cool Drink Factory (MVC) 7

The MVC Drink Factory: A recipe Requires: 3oz coconut milk 3oz almond milk 2 frozen bananas 2 tbsp peanut butter 1 tbsp agave nectar Place all ingredients in blender and blend for 45 seconds Serve in a pint glass, garnish with banana slice, cherry, and whipped cream (optional) 8

The MVC Drink Factory: Abstract What makes a drink? Ingredients Glasswear Recipe Recipe controls the entire process Ingredients make up the content of the drink Glass changes how you see the drink, but not its contents 9

The MVC Drink Factory Can make other drinks by changing the ingredients, keeping the steps to follow and the glass Can make also keep the ingredients and steps, change the presentation Same recipe, different presentation Same recipe, different ingredients 10

The MVC Modular Drink Factory My Very Cool factory separates concerns between recipes, ingredients, and glasses Different people can pull out ingredients, follow the recipe, and pour the result into the correct glass without knowing exactly what the other person does Could even completely replace how the ingredients are gathered (maybe use pre-portioned), and it doesn t effect the rest of the process 11

My Very Cool Drink Factory Wow, this separation of concerns is just what we want in our web apps! Because it s so modular, we named an entire design pattern based on this recipe, ingredient, presentation pattern (MVC) Alternatively, we might call it Model-View-Controller Model: Ingredients Controller: Recipe View: Glass/presentation 12

MV* Patterns The mother of them all: MVC Originally from 70's: UIs were just becoming possible... how to separate presentation from data and logic? Model: domain-specific data, doesn t matter how it s interacted with View: visual representation of current state of model Controller: Moderates user interactions, makes business decisions Separation of concerns 13

MVC & JavaScript DOM templates Glass/presentation JS that receives input from DOM, deploys spinner, etc. Recipe Ingredients Firebase todoref list Firebase callbacks that update view directly *Note that in drink factory, the glass doesn t care about the ingredients 14

MVVM View does not communicate with model directly Models are much more dumb: no formatting, etc ViewModel: like a controller from MVC, but only does data translation/formatting between M-V More directly maps to MyVeryCool Drink Factory than MVC does 15

MVC vs MVVM Low level controller/model code can be easily shared (especially in server apps) Views can have direct access to model Easier to develop in parallel (V only talks to VM) View is completely dumb and just needs data bindings 16

AngularJS Supports MVC/MVVM Provides structure to organize your code Two-way data binding Uses plain old objects for your data - no fancy structures needed HTML templating (like react) Designed for SPAs 17

Angular Documentation: Great 18

Directives & Data Binding Core feature of Angular Unlike React (add HTML to code), Angular lets us direct the html to have some code in it too Lets us add code into HTML Angular example: <!DOCTYPE html> <html lang="en" ng-app> <head> <meta charset="utf-8"> <title>my Angular Demo</title> Directives <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/ angular.js"></script> </head> <body> What's your name? <input type="text" data-ng-model="name" /> {{name}} </body> </html> Data Binding 19

Simple Data Binding Example 20

Other Directives 21

Other Directives ng-init Initialize variables within the scope of a DOM element ng-repeat Replicate a DOM element over an array 22

Filters Allow you to modify the text going into data bindings Only want to make simple modifications here Syntax: {{todo.text uppercase}} (Converts the todo to uppercase) <div ng-repeat="todo in todos orderby:'-priority' "> (Shows all todos ordered by key) Other uses: Select only some values in a list Order a list 23

Partials: A "Partial" HTML document Can be included into another with <nginclude> Example: <div> What's your name? <input type="text" data-ng-model="name"/> Hello, {{name}}! </div> partials/hello.html <ng-include src= partials/hello.html ></ng-include> index.html 24

Partials & Components User profile partial Who to follow partial Follow partial Feed partial Feed item partial 25

Partial Demo

Views, Controllers, Scopes Angular has a lot more than just views and directives Let s focus on controllers and scope 27

Angular Controllers Each controller is a function that gets passed $scope $scope is the bridge between the controller and view $scope is initially empty when the controller is called, and then it sets some properties on it When a view uses a controller, it inherits its $scope function TodoController($scope) { $scope.todos = [ { text: "Write more demos", priority: 5}, { text : "Add some gifs", priority: 10} ]; } 28

Views & Controllers Select a controller for a DOM element, and it will provide variables for everything contained in it Can have multiple controllers on one page <div class="todolist" data-ng-controller="todocontroller"> <div ng-repeat="todo in todos orderby:'-priority' "> {{todo.text uppercase}} </div> </div> <script> function TodoController($scope) { $scope.todos = [ { text: "Write more demos", priority: 5}, { text : "Add some gifs", priority: 10} ]; } </script> 29

Modules as Containers Module Config Routes Filter Directive Factory Service Provider Value Controller Modules contain everything that we need for a single component Organize views, controllers, etc. How do we make and use them? 30

Creating a Module Create a module and add a controller: var myapp = angular.module('demoapp', []); myapp.controller("todocontroller", TodoController); The empty array can instead specify dependencies Example dependency (a great one!): firebase Controllers should not stand on their own - must be part of module Module name must be the name provided in ngapp <html lang="en" data-ng-app= demoapp"> 31

Demo: Modules, Controllers, Firebase

Modules, Routes, Services 33

Routes Routes are paths from view/controllers to others Landing Page /#new New Todo /#landing /#categories Filter by category /#bycategory New Category 34

Routes AngularJS makes routes read like magic! myapp.config(function($routeprovider){ $routeprovider.when("/",{ controller: "TodoController", templateurl: "partials/editabletodos.html" }).when("/categories",{ controller: "CategoryController", templateurl: "partials/categories.html" }).otherwise({redirectto: "/"}); }); Reads like a sentence (chaining!) Dependency injection magic! 35

Partials Easy way to have "partial" HTML documents and combine them, magically-dynamically into one! Will be included by the route, into the container labeled with the directive <div data-ng-view></div>... myapp.config(function($routeprovider){ $routeprovider.when("/",{ controller: "TodoController", templateurl: "partials/editabletodos.html" }).when("/categories",{ controller: "CategoryController", templateurl: "partials/categories.html" }).otherwise({redirectto: "/"}); }); 36

Demo: Routes + Partials

Exit-Ticket Activity Go to socrative.com and select Student Login Class: SWE432001 (Prof LaToza) or SWE432002 (Prof Bell) ID is your @gmu.edu email 1: How well did you understand today's material 2: What did you learn in today's class? For question 3: How do you think you will use React in your HW this week?