Getting Started with Angular 2 and TypeScript Nebraska.Code() 2016 Spencer Schneidenbach Ryvit.

Slides:



Advertisements
Similar presentations
Validation in Angular 1.3 And other angular tidbits.
Advertisements

CIS101 Introduction to Computing Week 11. Agenda Your questions Copy and Paste Assignment Practice Test JavaScript: Functions and Selection Lesson 06,
@lestersconyers #spsevents #spsphx SPS EVENTS PHX SharePoint and Angular Sitting in a Tree… LESTER SCONYERS.
USING ANGULARJS WITH SITEFINITY
DHTML. What is DHTML?  DHTML is the combination of several built-in browser features in fourth generation browsers that enable a web page to be more.
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
Review IDIA 619 Spring 2013 Bridget M. Blodgett. HTML A basic HTML document looks like this: Sample page Sample page This is a simple sample. HTML user.
‘Tirgul’ # 7 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #7.
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.
INTRODUCTION TO JAVASCRIPT AND DOM Internet Engineering Spring 2012.
Essentials of HTML Class 4 Instructor: Jeanne Hart
Extending HTML CPSC 120 Principles of Computer Science April 9, 2012.
Introduction to Angular JS Sergey Barskiy Working Class Nobody Level: Introductory.
INTRODUCTION TO CSS. TOPICS TO BE DISCUSSED……….  Introduction Introduction  Features of CSS Features of CSS  Creating Style Sheet Creating Style Sheet.
Controllers and Markup Controllers, $scope, Markup, Directives, Expressions, Binding, Filters, Validation SoftUni Team Technical Trainers Software University.
Introduction to c++ programming - object oriented programming concepts - Structured Vs OOP. Classes and objects - class definition - Objects - class scope.
JAVASCRIPT WITH A VIEW Jordan Knight Solution Architect Xamling SESSION CODE: WEB305 (c) 2011 Microsoft. All rights reserved.
JQuery JavaScript is a powerful language but it is not always easy to work with. jQuery is a JavaScript library that helps with: – HTML document traversal.
Introduction to Angular James Kahng. Terms Framework Template/environment constructed in the language where you fill in details with code Library Set.
ASP.NET User Controls. User Controls In addition to using Web server controls in your ASP.NET Web pages, you can create your own custom, reusable controls.
Web Components with Polymer Jeff Tapper Digital
Getting Started with Aurelia
Adxstudio Portals Training
Programming Fundamentals. Topics to be covered Today Recursion Inline Functions Scope and Storage Class A simple class Constructor Destructor.
Session 2: Basic HTML HTML Coding Spring 2009 The LIS Web Team Presents.
Introduction to JavaScript MIS 3502, Spring 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 2/2/2016.
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.
LECTURE #4: JQUERY AND FORM VALIDATION Josh Kaine Josh Kaine 4/1/2016.
Modern Development Technologies in SharePoint SHAREPOINT SATURDAY OMAHA APRIL, 2016.
The New Face of ASP.NET ASP.NET MVC, Razor, and jQuery Ido Flatow | Senior Architect | Sela | This session is.
Best Web Technologies for
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.
Introduction to JavaScript MIS 3502, Fall 2016 Jeremy Shafer Department of MIS Fox School of Business Temple University 9/29/2016.
DHTML.
Learning About Angular
Angular 4 + TypeScript Getting Started
Creating Lightning Fast Apps Using AngularJS
Modern Web: Single Page Applications
Introduction to Redux Header Eric W. Greene Microsoft Virtual Academy
Play Framework: Introduction
AngularJS A Gentle Introduction John
Haritha Dasari Josue Balandrano Coronel -
Best Angular 2 interview questions and Answer that have been designed for Angular 2 programmers who are preparing online interviews on Angular 2 interviews question. Visit Website:
Not Sure how you Should React
The Cliff Notes Version
Jessica Betts, Sophia Pandey, & Ryan Amundson
SharePoint-Hosted Apps and JavaScript
AngularJS and SharePoint 2013: Lessons Learned from the Trenches
Angularjs Interview Questions and Answers By Hope Tutors.
Top Reasons to Choose Angular. Angular is well known for developing robust and adaptable Single Page Applications (SPA). The Application structure is.
Introduction to JavaScript
Displaying Form Validation Info
A second look at JavaScript
How AngularJS Development Services different from other Framework - Kunsh Technologies.
CS5220 Advanced Topics in Web Programming Angular – TypeScript
Chengyu Sun California State University, Los Angeles
Introduction to JavaScript
Angular 2 : CRUD Operations
Angular 2 Michael C. Kang.
Chengyu Sun California State University, Los Angeles
Introduce to Angular 6 Present by: Võ Văn Hào
Web Client Side Technologies Raneem Qaddoura
Bootstrap Direct quote from source: bootstrap/
Web Programming and Design
Web Programming and Design
Angular.
Modern Front-end Development with Angular JS 2.0
Presentation transcript:

Getting Started with Angular 2 and TypeScript Nebraska.Code() 2016 Spencer Schneidenbach Ryvit

About Me Platform Architect at Ryvit Consultant Web developer AngularJS 1/2, ASP.NET, C# Github: schneidenbach Website: schneids.net

Who are you to tell me? Building SPAs for 4 years Started with Angular 1 and ASP.NET Web API Using Angular 2 in production today

Setting the stage Building SPAs (single page apps) has never been easier Lots of framework choices! (yes, I know React is not a framework!)

Why Angular 2? Great SPA framework curated by Google Over Angular 1? Simpler Faster Lots of lessons learned from Angular 1 Angular 2 embraces the web

Angular 2 + TypeScript = <3 De facto language for Angular 2 Documentation Code examples Great, but not required! In the end, choose the language you’re comfortable with

What is TypeScript? A superset of JavaScript created by Microsoft Transpiles into JavaScript Focuses on: Application-scale language which adds type safety Modern features ES6 – classes, arrow functions ES7 – async/await ES?

Why TypeScript? Lots of neat features The future of JavaScript, today

Why not TypeScript? Yet another layer on top of JavaScript May not be around forever

Main reason why TypeScript is great “TypeScript doesn’t try to NOT be JavaScript – it just tries to make JavaScript better” –Spencer

So, let’s go over some TypeScript basics!

Variables Same as JavaScript… with a twist! Yes, it’s declared twice – and that’s totally valid Use let instead – it’s safer

Interfaces Classes without functionality – just like C#

Interfaces, cont’d Won’t let you compile with this type hint if you don’t fulfill the entire contract!

More interfaces Duck typing: “If it walks like a duck and quacks like a duck… it’s a duck” This is valid! And good! Respects JavaScript while adding safety

Classes Classes can define behaviors AND properties

Using classes

Constructor/property shorthand Adding an accessibility modifier to a parameter in the constructor automatically converts it to a property

Decorators Basically, attributes in C#/VB.NET Considered experimental feature – can only be turned on with compiler option

import/export Like using statements in C#/VB.NET import statements allow us to reference code from other TypeScript files export simply means public

Enough TypeScript! Angular 2 Time!

History lesson Angular 1 – started in 2009 Hugely popular – won the initial “SPA war”

Angular 1 to 2 - What’s changed? Controllers to components No more $scope ! Yay! Digest loop to unidirectional data flow Native event/property binding Way fewer custom directives Binding directly to DOM properties/events Simplified service model Easier to understand. Flatter learning curve.

Angular 1 to 2 – What stayed the same? Template syntax is very similar One-way data binding via interpolation {{ }} Still use directives in the same way Dependency injection is still used Directives and components… kinda

Directives Used to modify behavior of DOM elements Here is an attribute directive (from angular.io)

Components Components are directives with a template Angular 2 apps are built with components No more $scope, no more controller Functions/properties are bound directly from component

Components, cont’d Component scope is much easier to understand No more transclusion, isolate scope, etc. Functions/properties are bound directly from component Lots of smaller components > Fewer big components

Declaring a component Create your class Import the Component decorator Add a template and a selector

Templates in your component Templates contain the HTML that is rendered by your component Can be placed inline inside of Component declaration OR in a separate file

Styling a component You can add CSS directly to a component! DemoDemo

Styling a component, cont’d Bind CSS classes to an element like this If message.isUrgent is truthy, then the big-and-bold CSS class will be applied to the element

Ways to bind component to template Interpolation expressions Property binding Event binding ngModel

Interpolated expressions {{ }} syntax Put your expression inside the brackets Accepts non-side-effect-JavaScript (no new, assignments, etc.) Best use case – bind pure properties to it when possible

Property binding Bind directly to properties on the DOM model using [] The power and convenience of this cannot be understated! Allows something like this: To become this:

Property binding, cont’d Property binding means that all sorts of previous built-in directives in Angular 1 go away Ng1 DirectiveFunctionalityReplaced with ng-disabledDisables the control – used on inputs, selects, textareas [disabled]=“expression” ng-src/ng-hrefReplacement for src/href properties since interpolation didn’t play well with them [src]=“expression” [href]=“expression” ng-show/ng-hiddenHides/shows an element based on the truthiness of an expression [hidden]=“expression”

Event binding Bind directly to events on the DOM model using () Again, the power and convenience cannot be understated Support for custom events

Event binding, cont’d Property binding means that all sorts of previous built-in directives in Angular 1 go away Ng1 directiveFunctionalityReplaced with ng-clickBinds an expression to the click event(click)=“doSomething()” ng-changeBinds an expression to the input changed event (change)=“prop = $event” (ngModelChange)=“” ng-dblclickBinds an expression to the double click event(dblclick)=“onDoubleClick()” ng-mouseover…mouse over event ng-mousemove…mouse move event …you get the idea

ngModel Allows two-way binding Follows unidirectional data flow concepts Demo

Child components A child component is a component that exists within a component I know, pretty stunning right? Steps Easy: you make a component, then… Tell the parent about the component!

Step 1: Declare your component

Step 2: Import it to your parent component

Step 3: Register it with your parent component property: directives You must register the component’s type with the parent component!

Step 4: Add child selector to markup

Binding parent to child properties Means of binding data from the parent to the child Requires two steps Add property to child and decorate it Bind the parent property to the child using [] syntax

Step 1: Add the input property

Step 2: Bind the parent property to that property

Event emitting Parents can communicate with child components easily via input properties How does the child communicate with its parent? properties and EventEmitter! A little more to it properties, but very easy

Import and implement

Add subscribing function

Step 5 – Emit your event

What are Services? Services are best used to create, read, update and delete data Enforces separation of concerns Think of it like this: you don’t want your database in your view!

Services in Angular 1 In Angular 1, we had 5 different kinds of services: Provider Service Factory Value Constants In Angular 2, we have 1 kind of service: Service Which do you prefer?

Guess what? A service is just a class Are you surprised?

Step 1 – Make class with data

Step 2 – and decorate

Steps 3 and 4 – Import and register

Things we couldn’t cover Pipes Http service RxJS Forms Routing So much more!

There is lots more! angular2.schneids.net All code samples and code exercises from my workshop! Github: schneidenbach Website: schneids.net