Angular 2.

Slides:



Advertisements
Similar presentations
CSS The basics { }. CSS Cascading Style Sheets - language used to – describe html appearance & formatting Style Sheet - file that describes – how html.
Advertisements

Part 2 Introduction to CSS. CSS Syntax – class selector 1 With the class selector you can define different styles for the same type of HTML element. You.
CSS Link Styling. The Anchor Element: Link text between the opening and closing can be styled using CSS. Some of the properties that can be set are: font-family,
1/18 ITApplications XML Module Session 5: Extensible Stylesheet Language (XSL)
กระบวนวิชา CSS. What is CSS? CSS stands for Cascading Style Sheets Styles define how to display HTML elements Styles were added to HTML 4.0 to.
CSS normally control the html elements. Three Ways to Insert CSS There are three ways of inserting a style sheet: External style sheet Internal style.
Web Design with Cascading Style Sheet Lan Vu. Overview Introduction to CSS Designing CSS Using Visual Studio to create CSS Using template for web design.
Validation in Angular 1.3 And other angular tidbits.
Ch. 5 Web Page Design – Templates and Style Sheets Mr. Ursone.
Tutorial 13 Working with Objects and Styles. XP Objectives Learn about objects and the document object model Reference documents objects by ID, name,
User Interface Design using jQuery Mobile CIS 136 Building Mobile Apps 1.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Chapter 12 Creating and Using XML Documents HTML5 AND CSS Seventh Edition.
Dreamweaver MX. 2 Creating External Style Sheets-1 (p. 400) n A style is a group of formatting attributes identified by a single name. n An ________ style.
SUNY Polytechnic Institute CS 490 – Web Design, AJAX, jQueryAngularJS AngularJS is a client-side JavaScript Framework for adding interactivity to HTML.
Learning & Development Telerik Software Academy.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
Chapter 6 Understanding the Structure of an Application: Procedures, Modules, and Classes.
JavaScript Lecture 6 Rachel A Ober
ASP.NET Web Server Controls Basic Web Server Controls.
SEG3210 DHTML Tutorial. DHTML DHTML is a combination of technologies used to create dynamic and interactive Web sites. –HTML - For creating text and image.
 This presentation introduces the following: › 3 types of CSS › CSS syntax › CSS comments › CSS and color › The box model.
Form Tag How to use Form Tag Something NEW ? PARAMETER Attribute NAME Specifies the name for a form To specify which form to submit with JavaScript, this.
WRT235: Writing in Electronic Environments Basic CSS.
@ScotHillier Web Parts Workflows Pages Libraries App Parts SharePoint-Hosted Apps Provider-Hosted Apps.
ALBERT WAVERING BOBBY SENG. Week 2: HTML + CSS  Quiz  Announcements/questions/etc  Some functional HTML elements.
INTRODUCTION TO HTML5 Using jQuery with HTML5. Introducing jQuery  Although it is not a part of any W3C or WHATWG specification, jQuery performs an important.
Introduction to Angular JS Sergey Barskiy Working Class Nobody Level: Introductory.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Chapter 6 Introducing Cascading Style Sheets Principles of Web Design, 4 th Edition.
DOM Animation Changing the DOM objects over time.
Controllers and Markup Controllers, $scope, Markup, Directives, Expressions, Binding, Filters, Validation SoftUni Team Technical Trainers Software University.
>> More on CSS Selectors. Pre-requisite Open the file called sample.txt Copy the all the text from the file Open your browser and go to codepen.io Paste.
Partnership  excellence  growth WorldFish Center Survey Module.
DYNAMIC HTML What is Dynamic HTML: HTML code that allow you to change/ specify the style of your web pages. Example: specify style sheet, object model.
AngularJS Forms & validation. AngularJS form example First.
CIS 375—Web App Dev II ASP.NET 4 Server Controls.
CSE 154 LECTURE 9: THE DOM TREE. The DOM tree The elements of a page are nested into a tree-like structure of objects the DOM has properties and methods.
Getting Started with Angular 2 and TypeScript Nebraska.Code() 2016 Spencer Schneidenbach Ryvit.
AngularJS. What is AngularJS  Javascript Framework  MVC  for Rich Web Application Development  by Google.
ANGULAR 2. JavaScript is a high-level, dynamic, untyped, and interpreted programming language. JavaScript was originally developed in May 1995 by Brendan.
Angularjs 2.0 : Getting started
The building blocks of Angular
Learning About Angular
Services & Dependency Injection
WWU Hackathon May 6 & 7.
>> Introduction to CSS
>> CSS Rules Selection
WWU Hackathon May 6 & 7.
Web DevelopmEnt Angular 4
Build Better Apps with Angular 2.
Directives & Forms Capturing User Input SoftUni Team
JavaScript Forms Adding User Input.
Website Design 3
>> Dynamic CSS Selectors
The Internet 10/6/11 Cascading Style Sheets
Using Cascading Style Sheets (CSS)
Web Development Using ASP .NET
CS5220 Advanced Topics in Web Programming Angular – TypeScript
AngularJS Michael Kang August 20th 2015.
Chengyu Sun California State University, Los Angeles
Web API with Angular 2 Front End
Angular 2 : CRUD Operations
Angular 2 Michael C. Kang.
Chengyu Sun California State University, Los Angeles
CS5220 Advanced Topics in Web Programming Angular – Services
Focusing Your CSS Selectors
selector {style-name:value units;} </style>
Presentation transcript:

Angular 2

Modules app/app.component.ts: export class AppComponent { } app/boot.ts: import {AppComponent} from './app.component';

Library modules Angular apps are composed of modules. import {Component} from 'angular2/core'; Angular apps are composed of modules. Modules export things — classes, function, values — that other modules import. We prefer to write our application as a collection of modules, each module exporting one thing.

Component app/hero-list.component.ts export class HeroListComponent implements OnInit { constructor(private _service: HeroService){ } heroes: Hero[]; selectedHero: Hero; ngOnInit(){ this.heroes = this._service.getHeroes(); } selectHero(hero: Hero) { this.selectedHero = hero; }

Template app/hero-list.component.html <h2>Hero List</h2>   <p><i>Pick a hero from the list</i></p> <div *ngFor="#hero of heroes" (click)="selectHero(hero)"> {{hero.name}} </div> <hero-detail *ngIf="selectedHero" [hero]="selectedHero"> </hero-detail>

Metadata @Component({ selector: 'hero-list', templateUrl: 'app/hero-list.component.html', directives: [HeroDetailComponent], providers: [HeroService] }) export class HeroesComponent { ... } selector - a css selector that tells Angular to create and insert an instance of this component where it finds a <hero-list> tag in parent HTML: <hero-list></hero-list> Angular inserts an instance of the HeroListComponent view between tags. templateUrl - the address of this component's template directives - an array of the Components or Directives this template requires providers - an array of dependency injection providers for services that the component requires

Data binding app/hero-list.component <div>{{hero.name}}</div> <hero-detail [hero]="selectedHero”></hero-detail> <div (click)="selectHero(hero)></div>

Binding in templates Data Direction Syntax Binding Type One way from data source to view target   {{expression}} [target] = "expression" bind-target = "expr" Interpolation Property Attribute Class Style from view target to data source (target) = "expression" on-target = "expr" Event Two way [(target)] = "expr" bindon-target = "expr" Two-way

Binding targets Binding Type Target Examples Property Element Property <img [src] = "heroImageUrl"> Component Property <hero-detail [hero]="currentHero"></hero-detail> Directive property <div [ngClass] = "{selected: isSelected}"></div> Event Element Event <button (click) = "onSave()"> Save </button> Component Event <hero-detail (deleted)="onHeroDeleted()"> </hero-detail> Directive Event <div myClick (myClick)="clicked=$event">click me</div> Two-way Directive Event Property <input [(ngModel)]="heroName">

Binding Type Target Examples Binding targets Binding Type Target Examples Attribute Attribute (the exception) <button [attr.aria-label]="help"> help </button> Class class Property <div [class.special]="isSpecial"> Special </div> Style style Property <button [style.color] = "isSpecial ? 'red' : 'green'">

Service app/hero.service.ts export class HeroService { constructor( private _backend: BackendService, private _logger: Logger) { } private _heroes:Hero[] = []; getHeroes() { this._backend.getAll(Hero).then( (heroes:Hero[]) => { this._logger.log(`Fetched ${heroes.length} heroes.`); this._heroes.push(...heroes); // fill cache }); return this._heroes; } }

Dependency Injection constructor( private _service: HeroService) { … } But how Injector get to know about service? 2 ways: app/boot.ts bootstrap(AppComponent, [HeroService, Logger]); app/hero-list.component.ts @Component({ providers: [HeroService] }) export class HeroesComponent { ... } (we get a new instance of the service with each new instance of that component)

Forms <div class="form-group"> <label for="power">Hero Power</label> <select class="form-control" required> <option *ngFor="#p of powers" [value]="p">{{p}}</option> </select> </div> NgControl: <input type="text" class="form-control" required [(ngModel)]="model.name" ngControl="name" >

State Class if true Class if false Form validation Control has been visited ng-touched ng-untouched Control's value has changed ng-dirty ng-pristine Control's value is valid ng-valid ng-invalid .ng-valid[required] { border-left: 5px solid #42A948; /* green */ } .ng-invalid { border-left: 5px solid #a94442; /* red */ }

Show validation messages <input type="text" class="form-control" required [(ngModel)]="model.name" ngControl="name" #name="ngForm" > <div [hidden]="name.valid" class="alert alert-danger"> Name is required </div>

Routing @Component({ ... }) @RouteConfig([ {path:'/crisis-center', name: 'CrisisCenter', component: CrisisListComponent}, {path:'/heroes', name: 'Heroes', component: HeroListComponent}, {path:'/hero/:id', name: 'HeroDetail', component: HeroDetailComponent} ]) export class AppComponent { } <!-- Routed views go here --> <router-outlet></router-outlet>

Using pipes import {Component} from 'angular2/core' @Component({   @Component({ selector: 'hero-birthday', template: `<p>The hero's birthday is {{ birthday | date }}</p>` }) export class HeroBirthday { birthday = new Date(1988,3,15); // April 15, 1988 }

Define custom pipe import {Pipe} from 'angular2/core'; /* Raise the value exponentially * Takes an exponent argument that defaults to 1. * Usage: value | exponentialStrength:exponent * Example: * {{ 2 | exponentialStrength:10}} * formats to: 1024 */ @Pipe({name: 'exponentialStrength'}) export class ExponentialStrengthPipe { transform(value:number, args:string[]) : any { return Math.pow(value, parseInt(args[0] || '1', 10)); }  

Use custom pipe import {Component} from 'angular2/core'; import {ExponentialStrengthPipe} from './exponential-strength.pipe';   @Component({ selector: 'power-booster', template: ` <h2>Power Booster</h2> <p> Super power boost: {{2 | exponentialStrength: 10}} </p> `, pipes: [ExponentialStrengthPipe] }) export class PowerBooster { }

Use Async pipe import {Component} from 'angular2/core';   // Initial view: "Message: " // After 500ms: Message: You are my Hero!" @Component({ selector: 'hero-message', template: 'Message: {{delayedMessage | async}}', }) export class HeroAsyncMessageComponent { delayedMessage:Promise<string> = new Promise((resolve, reject) => { setTimeout(() => resolve('You are my Hero!'), 500); }); }