57
준비하세요 AngularJS 2.0

준비하세요 Angular js 2.0

Embed Size (px)

Citation preview

Page 1: 준비하세요 Angular js 2.0

준비하세요

AngularJS 2.0

Page 3: 준비하세요 Angular js 2.0

현재 버젼AngularJS 1.3

Page 4: 준비하세요 Angular js 2.0

Motivation for AngularJS 2.0

● 성능

● 웹의 변화

● 쓰기 편함

Page 5: 준비하세요 Angular js 2.0

성능

최초 AngularJS는 디자이너를 위해 만들어 졌다.

Page 6: 준비하세요 Angular js 2.0

웹의 변화

ES6

Web Components● Custom Elements● HTML Imports● Template Element● Shadow Dom

Page 7: 준비하세요 Angular js 2.0

쓰기 어려움

출처 http://www.bennadel.com/blog/2439-my-experience-with-angularjs-the-super-heroic-javascript-mvw-framework.htm

Page 8: 준비하세요 Angular js 2.0

AngularJS 2.0의 새로운 기능

Page 9: 준비하세요 Angular js 2.0

AtScript

Page 10: 준비하세요 Angular js 2.0

AtScript? 언어를 만드는거냐?더 어렵게 만들려는 수작이야?

Page 11: 준비하세요 Angular js 2.0
Page 12: 준비하세요 Angular js 2.0

module.directive('blink', ['$timeout', function($timeout) { return { require: 'options', restrict: 'A', link: function(_,element,__,options){ var selectors = someThirdPartyAPI(); element.query(selectors.join(',')) .forEach(e => options.apply(e)); } };}]);

Page 13: 준비하세요 Angular js 2.0

module.directive('blink', ['$timeout', function($timeout) { return { require: 'options', restrict: 'A', link: function(_,element,__,options){ var selectors = someThirdPartyAPI(); element.query(selectors.join(',')) .forEach(e => options.apply(e)); } };}]);

Page 14: 준비하세요 Angular js 2.0

module.directive('blink', ['$timeout', function($timeout) { return { require: 'options', restrict: 'A', link: function(_,element,__,options){ var selectors = someThirdPartyAPI(); element.query(selectors.join(',')) .forEach(e => options.apply(e)); } };}]);

Array<CssSelectors>

Element

Page 15: 준비하세요 Angular js 2.0

@Directive({ selector: ['[blink]']})class Blink { constructor(element:Element, options:Options, timeout:Timeout) { var selectors:Array<CssSelectors> = someThirdPartyAPI(); element.query(selectors.join(',')) .forEach(e => options.apply(e)); }}

Page 16: 준비하세요 Angular js 2.0

Introspection

Ideal Development Environment

MetadataOptionalTypes

AtScript

Page 17: 준비하세요 Angular js 2.0

ES3 '99- try/catch- RegExp

ES4 '07- Types- Classes- Modules- (other)

ES5 '09- strict mode

ES6 '15- Classes- Modules- (other)

ES? '??- Types- Annotation- Introspection

Page 18: 준비하세요 Angular js 2.0

AtScript- Annotations- Introspection

TypeScript- Types

ES6- classes- modules

ES5

Page 19: 준비하세요 Angular js 2.0

function Blink(element, options, timeout) {}

Blink.annotations = [ new Directive({selector: '[blink]'})];Blink.parameters = [ Element, Options, Timeout];

ES5

Page 20: 준비하세요 Angular js 2.0

class Blink { constructor(element, options, timeout) { }}Blink.annotations = [ new Directive({selector: '[blink]'})];Blink.parameters = [ Element, Options, Timeout];

ES6

Page 21: 준비하세요 Angular js 2.0

TypeScriptclass Blink { public static annotations = [ new Directive({selector: '[blink]'})];

public static parameters = [ Element, Options, Timeout];

constructor(element:Element, options:Options, timeout:Timeout) { }}

Page 22: 준비하세요 Angular js 2.0

AtScript@Directive({ selector: '[blink]'})class Blink { constructor(element:Element, options:Options, timeout:Timeout) { }}

Page 23: 준비하세요 Angular js 2.0

CoffeeScriptclass Blink { @annotations = [ new Directive({selector: '[blink]'})]; @parameters = [ Element, Options, Timeout]; constructor: (element, options, timeout){ }}

Page 24: 준비하세요 Angular js 2.0

AtScript != new language

AtScript = ES6 + Types + Annotations + Introspections

Page 25: 준비하세요 Angular js 2.0

Template

Page 26: 준비하세요 Angular js 2.0
Page 27: 준비하세요 Angular js 2.0

AngularJS 1.3<div ng-controller="SantaTodoController"> <input type="text" ng-model="newTodoTitle"> <button ng-click="addTodo()">+</button>

<tab-container> <tab-pane title="Tobias"> <div ng-repeat="todo in todosOf('tobias')"> <input type="checkbox" ng-model="todo.done"> {{todo.title}} <button ng-click="deleteTodo(todo)"> X </button> </div> </tab-pane> ...

Page 28: 준비하세요 Angular js 2.0

<div> <input type="text" [value]="newTodoTitle"> <button (click)="addTodo()">+</buton>

<tab-container> <tab-pane title="Good kids"> <div [ng-repeat|todo]="todosOf('good')"> <input type="checkbox" [checked]="todo.done"> {{todo.title}} <button (click)="deleteTodo(todo)"> X </button> </div> </tab-pane>...

AngularJS 2.0

Page 29: 준비하세요 Angular js 2.0

Event binding<button (click)="doSomething()">click me</button>

<div (^click)="doSomithing"> <img src="..."><span>text</span></div>

<zippy #zippy title="Greeting"> Body of the text which is shown conditionally. <a href (hover)="zippy.close()">hover to close</a>.</zippy><button (click)="zippy.toggle()">toggle</button>

Page 30: 준비하세요 Angular js 2.0

<div> <input type="text" [value]="newTodoTitle"> <button (click)="addTodo()">+</buton>

<tab-container> <tab-pane title="Good kids"> <div [ng-repeat|todo]="todosOf('good')"> <input type="checkbox" [checked]="todo.done"> {{todo.title}} <button (click)="deleteTodo(todo)"> X </button> </div> </tab-pane>...

AngularJS 2.0

Page 31: 준비하세요 Angular js 2.0

Property binding<div [property-name]="expression">

<div [ng-repeat|person]="people"> <span [text]="person.name"></span></div>

Page 32: 준비하세요 Angular js 2.0

<div> <input type="text" [value]="newTodoTitle"> <button (click)="addTodo()">+</buton>

<tab-container> <tab-pane title="Good kids"> <div [ng-repeat|todo]="todosOf('good')"> <input type="checkbox" [checked]="todo.done"> {{todo.title}} <button (click)="deleteTodo(todo)"> X </button> </div> </tab-pane>...

AngularJS 2.0

Page 33: 준비하세요 Angular js 2.0

<div> <input type="text" [value]="newTodoTitle"> <button (click)="addTodo()">+</buton>

<tab-container> <tab-pane title="Good kids"> <div [ng-repeat|todo]="todosOf('good')"> <input type="checkbox" [checked]="todo.done"> {{todo.title}} <button (click)="deleteTodo(todo)"> X </button> </div> </tab-pane>...

AngularJS 2.0

Page 34: 준비하세요 Angular js 2.0

Databinding

Databinding to Element`s propertiesnot to Element`s attributes

<elm attr=”...”> elm.property=...

Page 35: 준비하세요 Angular js 2.0

Controller

Page 36: 준비하세요 Angular js 2.0

controllers2009-2014

Page 37: 준비하세요 Angular js 2.0

Components= Building block (LEGO)

Page 38: 준비하세요 Angular js 2.0

<ng-search-icon>

<ng-paper-fab>

<ng-drawer-panel>

<ng-field>

Page 39: 준비하세요 Angular js 2.0

Directive Definition Object ("DDO")myModule.directive('directiveName', function factory(injectables) { return { priority: 0, template: '<div></div>', // or // function(tElement, tAttrs) { ... }, // or // templateUrl: 'directive.html', // or // function(tElement, tAttrs) { ... }, transclude: false, restrict: 'A', templateNamespace: 'html', scope: false, controller: function($scope, $element, $attrs, $transclude, otherInjectables) { ... }, controllerAs: 'stringAlias', require: 'siblingDirectiveName', // or // ['^parentDirectiveName', '?optionalDirectiveName', '?^optionalParent'], compile: function compile(tElement, tAttrs, transclude) { return { pre: function preLink(scope, iElement, iAttrs, controller) { ... }, post: function postLink(scope, iElement, iAttrs, controller) { ... } } // or // return function postLink( ... ) { ... } }, // or // link: { // pre: function preLink(scope, iElement, iAttrs, controller) { ... }, // post: function postLink(scope, iElement, iAttrs, controller) { ... } // } // or // link: function postLink( ... ) { ... } };});

Page 40: 준비하세요 Angular js 2.0

Component = Directive …그 지저분한 Directive 만 가지고 만들라고?

Page 41: 준비하세요 Angular js 2.0

Directive

Page 42: 준비하세요 Angular js 2.0

DDO2009-2014

Page 43: 준비하세요 Angular js 2.0

SantaTodoApp component@ComponentDirectiveclass SantaTodoApp { constructor() { this.newTodoTitle = ''; } addTodo: function() { ... } removeTodo: function(todo) { ... } todosOf: function(filter) { ... }}

Page 44: 준비하세요 Angular js 2.0

SantaTodoApp component@ComponentDirective({ ... })class SantaTodoApp { ... }

@TemplateDirective({ ... })class NgRepeat { ... }

@DecoratorDirective({ ... })class NgClass { ... }

Page 45: 준비하세요 Angular js 2.0

SantaTodoApp component@ComponentDirectiveclass SantaTodoApp { constructor() { this.newTodoTitle = ''; } addTodo: function() { ... } removeTodo: function(todo) { ... } todosOf: function(filter) { ... }}

Page 46: 준비하세요 Angular js 2.0

어? $scope 은 어딨지?

Page 47: 준비하세요 Angular js 2.0

$scope2009-2014

Page 48: 준비하세요 Angular js 2.0

컴포넌트의 모든 속성과 메소드는 템플릿에서 사용할 수 있

다.

Component is the execution context for the template

Page 49: 준비하세요 Angular js 2.0

Dependency Injection

Page 50: 준비하세요 Angular js 2.0

Defining servicesclass TodoStore { constructor(win:Window) { this.win = win; } add(todo) { // access this.win.localStorage ... } remove(todo) { ... } todosOf(filter) { ... }}

Page 51: 준비하세요 Angular js 2.0

angular.module2009-2014

Page 52: 준비하세요 Angular js 2.0

Using servicesimport {TodoStore} from './store';

@ComponentDirective({ directives: [TabContainer, TabPane, NgRepeat]})class SantaTodoApp { constructor(store:TodoStore) { ... } ...}

Page 53: 준비하세요 Angular js 2.0

Directives and DI<tab-container> <tab-pane title="Tobias"> New Macbook Pro Tesla Model X ... </tab-pane> <tab-pane title="Good kids"> ... </tab-pane> <tab-pane title="Bad kids"> ... </tab-pane></tab-container>

Page 54: 준비하세요 Angular js 2.0

Directives and DI

class TabContainer { constructor(tabs:Query<TabPane>) { ... } ...}

class TabPane { constructor( tabContainer:TabContainer, element:HTMLElement ) { ... } ...}

Page 55: 준비하세요 Angular js 2.0

요약

사망 : Controller, $scope, DDO, Module, jqLite

출생 : AtScript, Web Component 지원, more?

다이어트를 했다?

Page 56: 준비하세요 Angular js 2.0

Angular 2.0 Source

https://github.com/angular/angular