Professional Documents
Culture Documents
Angular 2 - S1ngS1ng
Angular 2 - S1ngS1ng
S1ngS1ng
Front End ● UI (User Interface)
○ User <==> Data access layer
Presentation Layer
Architecture ● Conventional VS SPA
● MVVM (MV*)
● Modulization
Angular 1 ●
●
Two-way data binding
Sementic tag
Framework! ● Dependency injection
● Test friendly
Framework!
Framework!
Angular 1 VS Angular 2
Angular 1 Angular 2
● Directives ● Less Directives
● Controllers ● Components
● Routing ● Routing
● $http ● HTTP
● $filter ● Pipes
● .factory, .service ● Services
● JavaScript ● TypeScript
Directives
Diff with Angular1 - Basic
Angular 1 Angular 2
//.html //.html
<body ng-controller="todoController as td"> <todo-list></todo-list>
<h3>{{td.todo.title}}</h3>
</body> //.ts
import {Component} from '@angular/core';
//.js
(function () { @Component({
angular.module('myApp').controller('todoController', todoController); selector: 'todo-list',
template: '<h3>{{todo.title}}</h3>'
function todoController () { });
var td = this;
td.todo = {id:1, title:'Learn Angular'}; export class todoComponent {
} todo = {id:1, title:'Learn Angular'};
})(); }
Understand Data-binding
Interpolation
One-way Binding
Component DOM
Event Binding
Two-way Binding
Diff with Angular 1 - Directives
Angular 1 Angualr 2
<ul> <ul>
<li ng-repeat="todo in td.todos | limitTo:2:0"> <li *ngFor="let todo of todos | splice:0:2">
{{todo.title}} {{todo.title}}
</li> </li>
</ul> </ul>
● JavaScript ● TypeScript
● (Dart, CoffeeScript) ● (JavaScript, Dart)
TypeScript
TS Code
import { cat } from 'animal';
constructor() {}
catMeow() {
return '=^o^=';
}
What is TS?
● Superset of JS
○ JS(ES5) < ES6 < TypeScript
● Static Language
○ Compile to JS
● Strongly Typed
○ Optional type declaration
● Features ES6
○ Arrow Function
JS: the Good and Bad
Good Bad
}
export class TodoList {
constructor (todoService) {
}
@Component({
selector: ‘todoApp’,
templateUrl: ‘./todo.html’,
Decorators style: `
})
import { Component } from
‘@angular/core’;
Import
import { TodoList} from ‘./todoList.
component’;
Back to Angular 2
Form
What is form
● Template-Driven
Form ● Half-half
● Model-Driven
HTML
driven ●
●
Data-binding
Error Message
Easy, straight-forward TS
● Action
In .html
Component- ●
●
Input elemnts
Control binding
driven In .ts
● Input elements
● Control binding
In .ts
Intermediate, easy to understand
● Controls
● Form
● Validation
Services
● Export class as service
○ @Injectable()
Services
● Inject service into component
○ constructor() or @Inject
● Provider: container of services
Example ● Recommend single initiation
○ Add to boostrap
Diff with Angular 1
Angular 1 Angular 2
● Factories ● Class
● Services
● Providers
● Constants
● Values
Router, HTTP
Router
● ROUTER_PROVIDERS,
ROUTER_DIRECTIVES,
RouterConfig
HTTP
● HTTP_PROVIDER, Http
● .map(), .json() .subscribe()
Eco-system
● Scaffold
● Code
Tools ● Test
● CSS Framework
All Free :) ● Deploy
Scaffold ●
●
Yeoman
Angular-seed
Basic structure, boilerplate
● Webstorm
Code ●
●
Visual Studio Code (recommend)
Sublime Text
Have fun coding :) ● Atom
Package Control ●
●
NPM
Bower
Dependency management
● Grunt
Task Runner ● Gulp
● NPM Script
Run ‘em all
● Jasmine
Test ●
●
Karma
Protractor (Selenium Server,
Framework and runner webdriver-manager)
● Bootstrap
○ Except IE8 or Opera Android and iOS
● Angular Material (alpha)
CSS Framework ●
○ n-1
Materialize
○ Chrome 35+, FF 31+, Safari 7+, IE 10+
EZ way to build stunning page
● Foundation
○ Except IE7 & IE8
● Concat, Minify
Deploy ● Tools
○ gulp
○ angular-cli
Pack, :ship-it: ○ webpack
Hello CLI ● Angular-CLI
FREE!!! XD
Lecturer: S1ngS1ng
Panelists: Lian Liu, Jerry Yang
Host: Shi H.
In Seatle?
Add lun to be in our local
discussion group
Keep in Touch!
GitHub: S1ngS1ng
LinkedIn: liuxing0514
Full-stack? Add xiao4742
to be in our WeChat: 1025583636
discussion
Front-end? group