IN4MATX 133: User Interface Software

Similar documents
By the end of this Angular 6 tutorial, you'll learn by building a real world example application:

One Framework. Angular

Angular 2 Programming

Before proceeding with this tutorial, you should have a basic understanding of HTML, CSS, JavaScript, TypeScript, and Document Object Model (DOM).

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

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

IN4MATX 133: User Interface Software

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

Lab 1 - Introduction to Angular

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

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

Angular 4 Training Course Content

AngularJS Fundamentals

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

Decoupled Drupal with Angular

Hands on Angular Framework

Comprehensive AngularJS Programming (5 Days)

Financial. AngularJS. AngularJS. Download Full Version :

Financial. AngularJS. AngularJS.

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

Setting up an Angular 4 MEAN Stack (Tutorial)

Advanced Angular & Angular 6 Preview. Bibhas Bhattacharya

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

Advantages: simple, quick to get started, perfect for simple forms, don t need to know how form model objects work

IN4MATX 133: User Interface Software

Mobile App Development

AngularJS Introduction

AngularJS AN INTRODUCTION. Introduction to the AngularJS framework

AngularJS Intro Homework

Comprehensive Angular 2 Review of Day 3

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

Understanding Angular Directives By Jeffry Houser

Angular from the Beginning

Angular 2 and TypeScript Web Application Development

PHP WITH ANGULAR CURRICULUM. What you will Be Able to Achieve During This Course

a Very Short Introduction to AngularJS

This course is designed for web developers that want to learn HTML5, CSS3, JavaScript and jquery.

IONIC. The Missing SDK For Hybrid Apps. Mike

Angular 2 and TypeScript Web Application Development

Sample Copy. Not For Distribution.

Integrating Angular with ASP.NET Core RESTful Services. Dan Wahlin

3 Days Training Program

Welcome to CS50 section! This is Week 10 :(

Angular2. Bernhard Niedermayer. Software Development playing around with Angular2 since alpha.

Angular 4 Syllabus. Module 1: Introduction. Module 2: AngularJS to Angular 4. Module 3: Introduction to Typescript

Modern and Responsive Mobile-enabled Web Applications

Angular 2. Useful links. Allen Holub 2-1

Stencil: The Time for Vanilla Web Components has Arrived

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

JavaScript. Like PHP, JavaScript is a modern programming language that is derived from the syntax at C.

Single Page Applications using AngularJS

CUSTOMER PORTAL. Custom HTML splashpage Guide

User Interaction: jquery

Frontend UI Training. Whats App :

Full Stack boot camp

Upgrading to Ionic 3 APPENDIX D. Angular 4

JavaScript and MVC Frameworks FRONT-END ENGINEERING

20486: Developing ASP.NET MVC 4 Web Applications

DNCMagazine. ANGULAR. Cheat Sheet

Full Stack Web Developer

20486-Developing ASP.NET MVC 4 Web Applications

An Brief Introduction to a web browser's Document Object Model (DOM) Lecture 20 COMP110 Spring 2018

Angular University Learn and Keep Up With The Angular Ecosystem

Web Software Model CS 4640 Programming Languages for Web Applications

Ten good practices for ASP.NET MVC applications

Static Webpage Development

Introduction to WEB PROGRAMMING

We will talk about Alt-Tab from the usability perspective. Think about: - Is it learnable? - Is it efficient? - What about errors and safety?

Angular 5 vs. React When to Choose Which?

FRONT END WEB. {< Course Details >}

Unit 3 - Week 2 lectures: Building your webapp

PHP + ANGULAR4 CURRICULUM 6 WEEKS

The DOM and jquery functions and selectors. Lesson 3

Getting Started with

Course 20486B: Developing ASP.NET MVC 4 Web Applications

Developing ASP.NET MVC 4 Web Applications

ADVANCED JAVASCRIPT #8

Developing ASP.NET MVC 4 Web Applications

Sample CS 142 Midterm Examination

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

ASP.NET MVC Training

Catbook Workshop: Intro to NodeJS. Monde Duinkharjav

Dreamweaver CS4. Introduction. References :

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

Ten interesting features of Google s Angular Project

Lecture 4. Ruby on Rails 1 / 52

week8 Tommy MacWilliam week8 October 31, 2011

High Performance Single Page Application with Vue.js

Chapter 1 - Model Driven Forms

An Brief Introduction to a web browser's Document Object Model (DOM) Lecture 24

CSC 309 The Big Picture

Jim Jackson II Ian Gilman

Vue.js Framework. Internet Engineering. Spring Pooya Parsa Professor: Bahador Bakhshi CE & IT Department, Amirkabir University of Technology

Developing ASP.Net MVC 4 Web Application

DATABASE SYSTEMS. Introduction to web programming. Database Systems Course, 2016

D3 + Angular JS = Visual Awesomesauce

CS142 Winter 2017 Midterm Grading Solutions and Rubric

Scheduling WebEx Meetings with Microsoft Outlook

ANGULARJS INTERVIEW QUESTIONS

COURSE 20486B: DEVELOPING ASP.NET MVC 4 WEB APPLICATIONS

Transcription:

IN4MATX 133: User Interface Software Lecture 13: Components in Angular Professor Daniel A. Epstein TA Jamshir Goorabian TA Simion Padurean 1

Notes Important: please put your name/email/id in the readme.txt file for A2 We re finishing up A1 grading, out soon Maybe Monday A3 will also be posted soon Later today or over the weekend 2

Today s goals By the end of today, you should be able to Explain a Model-View-Controller Architecture and how Angular implements the architecture Describe the role of an Angular component Implement an Angular component which follows the MVC architecture 3

Client-side Server-side Runs in the browser Runs in the command line, etc. (but maybe can still be accessed from the browser) Changes happen in real-time in the browser Changes happen in response to HTTP requests Cannot make HTTP requests to many APIs Can make HTTP requests to most APIs Examples: AJAX, Angular, React, Vue.js Examples: Node, ASP.NET 4

A small client interface 3 pages No interactivity between pages Data is dynamic, but UI is fairly static A lot of computation behind each page, but each page was very self-contained 5

A large client interface Hundreds of pages and ways to navigate between pages Repeated UI components (status updates) Different content, links, etc. displayed for each person 6

How do we develop large client applications? 7

Frameworks for large clients Add structure and organization Make UI components reusable Support modularity Import packages, UIs, etc. when needed 8

Frameworks for large clients Angular React Vue.js All support the same overall goal 9

Angular First released in 2009 Uses TypeScript, HTML, and CSS Does not dictate what framework is used server-side Latest release was last week (October 18, 2018; Version 7) Minor update, mostly improvements to performance and the command-line interface 10

Angular!= AngularJS Major rewrite in 2016 Move to TypeScript from JavaScript Not backwards-compatible Makes searching StackOverflow a bit of a pain But the syntax maps over reasonably okay 11

Angular installation npm install -g @angular/cli Create a new app with name example ng new example Run app cd example ng serve (--open) (Runs on localhost:4200 by default) 12

Angular architecture 13

Model-View-Controller Approach for structuring the code behind interfaces Model: the data behind an app View: the visual interface of an app Controller: the interaction with an app https://en.wikipedia.org/wiki/model%e2%80%93view%e2%80%93controller 14

Model-View-Controller Model: the data behind an app Notifies views when it changes Enables views to query the model for data Allows the controller to manipulate data in the model https://en.wikipedia.org/wiki/model%e2%80%93view%e2%80%93controller 15

Model-View-Controller View: the visual interface of an app Renders the contents of the model Specifies how the model data should be presented When the model changes, the view must update it s presentation Push approach: the view waits for change notifications (live updating feed) Pull approach: the view must ask when it wants new data (pull to refresh) Forwards input to the controller https://en.wikipedia.org/wiki/model%e2%80%93view%e2%80%93controller 16

Model-View-Controller Controller: the interaction with an app Interprets user input and maps them to actions Tells the model what actions to perform Tells the view if page should be rendered differently https://en.wikipedia.org/wiki/model%e2%80%93view%e2%80%93controller 17

Model-View-Controller Model: JavaScript for loading, parsing, and manipulating data View: HTML and CSS to specify layout Controller: event handlers for buttons and inputs in JQuery https://en.wikipedia.org/wiki/model%e2%80%93view%e2%80%93controller 18

MVC in Angular View: HTML and CS Model & Controller: TypeScript Angular functionality serves as the glue between the three https://codeburst.io/angularjs-4-101-6675076784aa 19

MVC in Angular Binding: key term Variables in a view can be bound to variables and functions in a model or controller When a variable in the model changes, any references to it in the view will also change ( push model) When a view receives input from a user, it passes it to controller bound for that input https://codeburst.io/angularjs-4-101-6675076784aa 20

Following MVC in Angular 21

Angular components A component is an interface element Usually larger than a button, but smaller than a page Usually one which repeats across the interface 22

Angular components Component terms template: the HTML file representing the view style: the CSS file(s) which indicate how the component should be styled selector: a CSS selector that Angular will use to all instances with this component 23

Angular components Defines the model, view, and controller for any interface element Make a new component: ng generate component hello Each component makes a folder consisting of four files: hello.component.css (view) hello.component.html (view) hello.component.spec.ts (for automated testing; we ll mostly ignore) hello.component.ts (model and controller) 24

Angular components Every app has at least one component Root component By default, in app.component.(html/css/ts/spec.ts) The main page in your app, essentially 25

Root template app.component.html <div style="text-align:center"> <h1> Welcome to {{ title }}! </h1> <img width="300" alt="angular Logo" src= data:image/... > </div> <h2>here are some links to help you start: </h2> <ul> <li> <h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">tour of Heroes</a></h2> </li> <li> <h2><a target="_blank" rel="noopener" href="https://github.com/angular/angular-cli/wiki">cli Documentation</a></h2> </li> <li> <h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">angular blog</a></h2> </li> </ul> <router-outlet></router-outlet> 26

Root template app.component.html Looks like any other HTML page Only difference: page can support data binding 27

Root template app.component.html <div style="text-align:center"> <h1> Welcome to {{ title }}! Binds text to the variable title </h1> <img width="300" alt="angular Logo" src= data:image/... > </div> <h2>here are some links to help you start: </h2> <ul> <li> <h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">tour of Heroes</a></h2> </li> <li> <h2><a target="_blank" rel="noopener" href="https://github.com/angular/angular-cli/wiki">cli Documentation</a></h2> </li> <li> <h2><a target="_blank" rel="noopener" href="https://blog.angular.io/">angular blog</a></h2> </li> </ul> <router-outlet></router-outlet> 28

Root component app.component.html import { Component } from '@angular/core'; Import Angular component library @Component({ Designates class as a component selector: 'app-root', Replace all occurrences of app-root with this templateurl: './app.component.html', Designate template styleurls: ['./app.component.css'] Designate style(s) }) export class AppComponent { All code for the component title = 'example'; } 29

Root component and template app.component.html app.component.ts <div style="text-align:center"> <h1> Welcome to {{ title }}! </h1> <img width="300" alt="angular Logo" src= data:image/... > </div> <h2>here are some links to help you start: </h2> <ul> <li> <h2><a target="_blank" rel="noopener" href="https:// angular.io/tutorial">tour of Heroes</a></h2> </li> <li> <h2><a target="_blank" rel="noopener" href="https:// github.com/angular/angular-cli/wiki">cli Documentation</a></ h2> </li> <li> <h2><a target="_blank" rel="noopener" href="https:// blog.angular.io/">angular blog</a></h2> </li> </ul> <router-outlet></router-outlet> Bound to import { Component } from '@angular/core'; @Component({ selector: 'app-root', templateurl: './ app.component.html', styleurls: ['./ app.component.css'] }) export class AppComponent { title = 'example'; } 30

Four types of binding Interpolation: {{ }} Property: [] Event: ( ) Two-way: [( )] https://angular.io/guide/template-syntax 31

Interpolation binding {{ }} Weave calculated strings into the text between HTML element tags and within attribute assignments <h3> {{title}} <img src="{{heroimageurl}}" style="height:30px"> </h3> Can also be used to calculate values <!-- "The sum of 1 + 1 is 2" --> <p>the sum of 1 + 1 is {{1 + 1}}</p> https://angular.io/guide/template-syntax 32

Property binding [ ] Set an element property to a component property value <img [src]="heroimageurl"> https://angular.io/guide/template-syntax 33

Event binding ( ) Listen for certain events such as keystrokes, mouse movements, clicks, and touches <!--When clicked, will run the onsave() function in component.ts file--> <button (click)= onsave()">save</button> https://angular.io/guide/template-syntax 34

One-way binding Interpolation, property, and event are all one-way, or read-only binding For interpolation {{ }} and property [ ], binding goes from data source (.ts) to view target (.html) For event ( ), binding goes from view target (.html) to data source (.ts) https://angular.io/guide/template-syntax 35

One-way binding {{title}} <img [src]="heroimageurl"> Bound to Bound to <button (click)="onsave()">save</button> Bound to import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-hello', templateurl: './hello.component.html', styleurls: ['./hello.component.css'] }) export class HelloComponent implements OnInit { title = 'example'; heroimageurl = 'hero.jpg'; constructor() { } ngoninit() { } onsave() { console.log('file saved!'); } } https://angular.io/guide/template-syntax 36

Question Which will bind the link s href to the link is the variable url? A B C D E <a href= {{url}} >link</a> <a (href)= url >link</a> <a [href]= url >link</a> A and B A and C 37

Two-way binding [( )] You often want to both display a data property and update that property when the user makes changes Most common use: binding to user-generated input ngmodel directive enables two-way binding to input fields <!--enteredtext variable contains inputted text--> <!--textchanged() is called after every keystroke--> <input [(ngmodel)]="enteredtext" (change)="textchanged()"> https://angular.io/guide/template-syntax 38

Binding <!--enteredtext variable contains inputted text--> <!--textchanged() is called after every keystroke--> <input [(ngmodel)]="enteredtext" (change)="textchanged()"> <!--When clicked, will run the onsave() function in component.ts file--> <button (click)="onsave()">save</button> <h3> <!--will display the title--> {{title}} <!--will display the image at heroimageurl--> <img [src]="heroimageurl"> </h3> 39

*ngif Render a tag if condition is true <p *ngif="ishalloween"> Spooky! </p> Can use ternary operator <div [style.display]="isspecial? 'block' : 'none'">show with style</div> 40

*ngfor Repeat an item multiple times <ul> <li *ngfor="let day of days"> {{day}} </li> </ul> Can optionally specify index <ul> <li *ngfor="let day of days; let i=index"> {{i+1}}: {{day}} </li> </ul> //In component.ts days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; 41

Using components Components can import other components Follow the selector defined in the component s.ts file In app.component.html: <div> <h1> Welcome to {{ title }}! </h1> <app-day></app-day> </div> <router-outlet></router-outlet> 42

Using components Components can specify inputs import { Component, OnInit, Input } from '@angular/core'; @Component({ selector: 'app-day', templateurl: './day.component.html', styleurls: ['./day.component.css'] }) export class DayComponent { @Input() today:string; Input <ul> <li *ngfor="let day of days"> {{day}} <strong *ngif="day == today">today!</strong> </li> </ul> Input referenced in.html days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]; } constructor() { } 43

Using components Inputs are then passed: As properties if they re dynamic Like any other attribute if they re static <div> <h1> Welcome to {{ title }}! </h1> <app-day [today]="dayofweek"></app-day> </div> Sets day property to dayofweek variable <div> <h1> Welcome to {{ title }}! </h1> <app-day today="friday"></app-day> </div> Sets day property static value Friday 44

Using components Can also specify output properties @Output('myClick') clicks = new EventEmitter<string>(); When adding component, can specify an event to trigger when clicks() is called <app-button (myclick)="clickmessage">click with myclick</ app-button> The event will be triggered in the parent component clickmessage() { } console.log("clicked!"); 45

oninit() vs Constructor Most components have both a constructor and an oninit() function Better to put any setup code in oninit() which occurs later import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-hello', templateurl: './hello.component.html', styleurls: ['./hello.component.css'] }) export class HelloComponent implements OnInit { constructor() { } } ngoninit() { } https://stackoverflow.com/questions/35763730/difference-between-constructor-and-ngoninit 46

Summary Angular is made up of components, which are UI elements which each follow a Model-View-Controller framework.html and.css file define the view.ts defines the model and controller Data moves between model and view through binding Components can pass data by binding Inputs and Outputs Components can include other components *ngif and *ngfor help determine whether and how many components to create 47

Today s goals By the end of today, you should be able to Explain a Model-View-Controller Architecture and how Angular implements the architecture Describe the role of an Angular component Implement an Angular component which follows the MVC architecture 48

IN4MATX 133: User Interface Software Lecture 13: Components in Angular Professor Daniel A. Epstein TA Jamshir Goorabian TA Simion Padurean 49