SlideShare ist ein Scribd-Unternehmen logo
1 von 20
Angular 2 RC5 조사
by RYU
(신림 프로그래머 모임)
참고 자료
• https://angular.io/docs/ts/latest/guide/architecture.html
• http://learnangular2.com
Angular 2를 감히 말하자면…
• Angularjs2는 Javscript 및 Typescript, Dart와 같은 Javascript로 컴파일 되
는
언어로 Html안에서 Client Application을 만들기 위한 Framework
• 몇 개의 코어와 몇 개의 부가적인 라이브러리로 구성 되어 있다.
• Component 클래스를 이용하여 앵귤라화 된 Html 템플릿과 템플릿을
관리 하고, 컴포넌트를 관리하고 서비스의 로직을 추가 할 수 있다.
• 최상위 모듈을 이용해 어플리케이션을 구동시킬 때 Angularjs는 브라우져에
어플리케이션을 출력하고 사용자에 행동에 따라 당신이 지정해 놓은 사용자
반응을 응답한다.
Angular 2 Architecture Overview
Angular 2: 8가지 주요 요소
• Modules
• Components
• Templates
• Metadata
• Data binding
• Directives
• Services
• Dependency injection
Ionic Team이 소개하는 특징
• COMPONENT
• INPUTS
• OUTPUTS
• APP LIFECYCLE
• TEMPLATES
• EVENTS
• FORMS
• VIEWCHILD
# ANGULAR 2: COMPONENT
컴포넌트는 페이지에 로직과 페이지에 엘리먼트를 구체화할수 있는 주
요한 방법이다. 앵귤라1에서 directives, controllers, and scope를 통
해서 구현하였다면 앵귤러2 에서 해당 컨셉은 Components로 통합되
었다.
import
{ Component } from
'@angular/core';
@Component({
selector: 'my-app',
template: '<h1>My
First Angular 2
App</h1>'
})
export class
AppComponent { }
import { NgModule } from '@angular/core';
import { BrowserModule } from
'@angular/platform-browser';
import { AppComponent } from
'./app.component';
import { OtherAppComponent } from
'./otherapp.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
import { platformBrowserDynamic }
from '@angular/platform-browser-
dynamic';
import { AppModule } from
'./app.module';
import { OtherAppModule } from
'./otherapp.module';
platformBrowserDynamic().boots
trapModule(AppModule);
platformBrowserDynamic().bootstra
pModule(OtherAppModule);
# ANGULAR 2: COMPONENT
<html>
<head>
<title>Angular 2 QuickStart</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->
<body>
<my-app>Loading...</my-app>
<other-my-app>Loading...</other-my-app>
</body>
</html>
/**
/**
* System configuration for Angular 2 samples
* Adjust as necessary for your application needs.
*/
(function(global) {
// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'@angular': 'node_modules/@angular',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-
web-api',
'rxjs': 'node_modules/rxjs'
};
// packages tells the System loader how to load when no filename
and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension:
'js' },
};
var ngPackageNames = [
'common',
'compiler',
'core',
'forms',
'http',
'platform-browser',
'platform-browser-dynamic',
'router',
'router-deprecated',
'upgrade',
];
// Individual files (~300 requests):
function packIndex(pkgName) {
packages['@angular/'+pkgName] = { main: 'index.js',
defaultExtension: 'js' };
}
// Bundled (~40 requests):
function packUmd(pkgName) {
packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName
+ '.umd.js', defaultExtension: 'js' };
}
// Most environments should use UMD; some (Karma) need the
individual index files
var setPackageConfig = System.packageWithIndex ? packIndex :
packUmd;
// Add package entries for angular packages
ngPackageNames.forEach(setPackageConfig);
var config = {
map: map,
packages: packages
};
System.config(config);
})(this);
# ANGULAR 2: INPUTS
앵귤러 2 어플리케이션에서 코어는 컴포턴트들이긴 하지만 대부분 개
발자들은 동적으로 설정하여 컴포넌트에 어떻게 데이터를 넣어줄지 필
요할것이다. (컴포넌트 동적 프로퍼티 변경)
@Input
컴포넌트에 'input'을 정의하기 위해서 '@Input'표시자를 써야 한다 .
import { Component, Input } from '@angular/core';
@Component({
selector: 'my-number',
template: '<div><p> The next number is {{ mynumber + 1}} </p></div>'
})
export class MyNumberComponent {
@Input() mynumber: number;
}
@Component({
selector: 'MyNumberRootComponent',
directives: [MyNumberComponent],
template: `<my-number [mynumber]="42"></my-number>`
})
export class MyNumberRootComponent {}
# ANGULAR 2: OUTPUTS
특별한 이벤트를 바인딩 할때 앵귤러 2에서는 이벤트 문법을 사용하여
처리 할 수 있지만. 필요한 커스텀 이벤트를 작성할때 @Output 지시자
를 사용하면 된다. ( 이벤트 동적 바인딩 )
import { Component, Output, EventEmitter } from '@angular/core';
@Component({
selector: 'zippy',
template: `
<div class="zippy">
<button (click)="toggle()">눌러봐 ~</button>
<div [hidden]="!visible">@Output 데코레이터를 통한 이벤트 동적 바인딩 </div>
</div>`
})
export class Zippy {
visible: boolean = true;
@Output() open: EventEmitter<any> = new EventEmitter();
@Output() close: EventEmitter<any> = new EventEmitter();
toggle() {
this.visible = !this.visible;
if (this.visible) {
this.open.emit(null);
} else {
this.close.emit(null);
}
}
# ANGULAR 2: APP LIFECYCLE
ANGULAR는 다단계에 걸친 기동과 lifecycle 과정을 통해 시작되며 어플리케이
션이 시작/동작 컴포넌트의 생성과 소멸 될 때 다양한 이벤트를 받을 수 있다.
BOOTSTRAP
Angular 2 어플리케이션들은 the root component를 통해 기동된다.
COMPONENT INIT
컴포넌트가 생성될때 그것에 생성자는 호출된다. 이것은 우리에 컴포넌트를 위한 초기화 영역이다. 그
러나
자식 컴포넌트부터 데이터나 속성에 의존되어 있다면 자식 컴포넌트가 먼저 초기화 하는 것을 기다려야
한다. 컴포넌트는 설정이나 어플리케이션 코드에 들어갈수 있다 컴포넌트들의 템플릿들은 전체 어플리
케이션에
연결이 생성 되는 곳에 있다. 'ngOnInit' lifecycle event을 통해서 이런 부분을 컨트롤 할수 있고 추가적
으로
setTimeout에서 호출하면서 생성자와 비슷한 효과를낼수 있다.
COMPONENT LIFECYCLE
'ngOnInit' 같이 우리는 컴포넌트에 lifecycle 을 통해 몇가지 이벤트를 추적 할수 있다.
# ANGULAR 2: APP LIFECYCLE
import { Component } from '@angular/core';
@Component({
selector: ‘app-lifecycle',
template: `
<div class="lifecycle">해당 컴포넌트 호출시 일어나는 이벤트
</div>`
})
export class Zippy {
ngOnInit() {
console.log("call ngOnInit in Zippy Component");
// Properties are resolved and things like
// this.mapWindow and this.mapControls
// had a chance to resolve from the
// two child components <map-window> and <map-
controls>
}
ngOnDestroy() {
console.log("call ngOnDestroy in Zippy Component");
// Speak now or forever hold your peace
}
ngDoCheck() {
console.log("call ngDoCheck in Zippy Component");
// Custom change detection
}
ngOnChanges(changes) {
console.log("call ngOnChanges in Zippy Component");
// Called right after our bindings have been checked but only
// if one of our bindings has changed.
//
// changes is an object of the format:
// {
// 'prop': PropertyUpdate
// }
}
ngAfterContentInit() {
console.log("call ngAfterContentInit in Zippy Component");
// Component content has been initialized
}
ngAfterContentChecked() {
console.log("call ngAfterContentChecked in Zippy
Component");
// Component content has been Checked
}
ngAfterViewInit() {
console.log("call ngAfterViewInit in Zippy Component");
// Component views are initialized
}
ngAfterViewChecked() {
console.log("call ngAfterViewChecked in Zippy
Component");
// Component views have been checked
}
…
# ANGULAR 2: TEMPLATES
템플릿은 좀더 명확하게 작지만 많은 문법 변화가 일어났지만 앵귤라1 과 아주 흡사하다
- {}: RENDERING
standard double-curly syntax 값을 출력한다.
- []: BINDING PROPERTIES
component에 변수를 맵핑 하기 위해서 '[]' 문법을 사용한다. 만약 우리에
컴포턴트에 this.currentVolume 값이 있을 때, 컴토넌트를 통해서 값을
넘겨주고 값들이 계속 동기화된다.
- (): HANDLING EVENTS
'()' 신텍스를 통해서 이벤트를 컴포넌트에서 처리할수 있다.
- [()]: TWO-WAY DATA BINDING
다른 이벤트나 사용자의 입력을 통해서 변경을 유지하기 위해 '[()]' 문법을 사용하고
property를 연결하거나 이벤트처리에 대한 조합을 생각할수 있다.
- *: THE ASTERISK
'*'는 template로써 directive가 component를 다룰수 있는 것을 말한다. 전처럼 그리지는 않는다. 예를 들어
'ngFor'는 <my-component> 를 취해서 아이템리스트를 출력한다. 그러나 초기화는 하지 않는다. 몇몇
비슷한 다른 directives는 template에서 *ngIf, *ngSwitch보다 더 좋게 동작한다.
# ANGULAR 2: TEMPLATES
<div> Hello my name is {{name}} and I like {{thing}} quite a lot. </div>
<video-control [volume]="currentVolume"></video-control>
<my-component (click)="onClick($event)"></my-component>
<input [(ngModel)]="myName">
<my-component *ngFor="#item of items"> </my-component>
{}: RENDERING
[]: BINDING PROPERTIES
(): HANDLING EVENTS
[()]: TWO-WAY DATA BINDING
*: THE ASTERISK
# ANGULAR 2: EVENTS
Angular2 에서의 이벤트는 템플릿 안에서 괄호 표현식을
사용하며 컴포턴트 클래스 안에 메소드와 연결되어 있다.
DELEGATION (위임)
Angular2 에서의 이벤트는 일반적인 DOM이벤트와 비슷하게 동작한다. 이벤트를 상향으
로 올리거나 아래로 전파할 수 있으며 특별한게 없다.
EVENT OBJECT
이벤트를 처리 할 때 '$event'라는 파라메터로 템플릿에 이벤트 콜백(함수)로 처리한다.
# ANGULAR 2: EVENTS
import { Component } from '@angular/core';
@Component({
selector: 'keyup-event1',
template: `<input (keyup)="onKey($event)"/><p>{{value}}</p>`
})
export class KeyUpComponent_v1 {
value = '';
onKey(event: KeyboardEvent){
this.value += (<HTMLInputElement>event.target).value + '|';
}
}
<html>
<head>
<title>Angular 2 Components Simple Example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1">
<link rel="stylesheet" href="styles.css">
<!-- 1. Load libraries -->
<!-- Polyfill(s) for older browsers -->
<script src="node_modules/core-
js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-
metadata/Reflect.js"></script>
<script
src="node_modules/systemjs/dist/system.src.js"></script>
<!-- 2. Configure SystemJS -->
<script src="componentexample.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
</head>
<!-- 3. Display the application -->
<body>
<click-component>Loading...</click-component>
<keyup-event1>Loading...</keyup-event1>
</body>
</html>
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { ClickComponent } from './componentexample.component';
import { KeyUpComponent_v1 } from './keyupevent.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [
ClickComponent,
KeyUpComponent_v1
],
bootstrap: [ ClickComponent,KeyUpComponent_v1 ]
})
export class ComponentExampleModule { }
# ANGULAR 2: FORMS
SIMPLE FORM
FORMBUILDER
The FormBuilder from the example above makes it easy for us to specify form controls and the various validators
we might want to apply to certain controls. In the example above, we are creating two inputs, an email and
password field:
CONTROLGROUP
The FormBuilder creates instances of ControlGroup, which we refer to as a form. Instead of using the FormBuilder,
we could also construct the ControlGroup manually: In practice though, the FormBuilder is what we will use to
quickly create forms.
FORM DIRECTIVES
You’ll notice the lack of ngModel anywhere in our form. Instead, we have the ngControl decorators that map
certain inputs to our control objects: This “binds” the email input to the instance of our email control.
CUSTOM VALIDATORS
We can build custom form validators as a simple function:
HANDLING FORM
We can easily get the simple Javascript object value of our form, or the value of an individual control:
# ANGULAR 2: VIEWCHILD
ANGULAR 2에서 모든 컴포넌트들이 클래스를 가지기 떄문
에 클래스 안에 메소드를 호출한다. 이것으로 인해 컴포넌
트에 접근할수 있다. (쉽게 말해서 컴포넌트에서 컴포넌트
접근)
@ViewChild
Component과 그 것들의 method들을 접근하기 위해
@ViewChild 어노테이션을 쓸수 있다.
예를 들어 <user-profile> component가 sendData()라는
메소드를 호출 가능하다면 우리에 페이지에서 user-profile
를 사용할 때 클래스에 참조가능하며 지역 변수로 그것을
할당 가능하다.
# ANGULAR 2: VIEWCHILD
@Component({ selector: 'user-profile' })
export class UserProfile {
sendData(){ //send data
}
}
import { Component, ViewChild } from '@angular/core';
import { UserProfile } from '../user-profile';
@Component({
template: '<user-profile (click)="update()"></user-profile>', directives: [UserProfile]
}) export class MasterPage {
@ViewChild(UserProfile) userProfile: UserProfile
update(){
this.userProfile.sendData();
}
}
미흡한 자료를 봐주셔서
감사합니다. Orz

Weitere ähnliche Inhalte

Was ist angesagt?

Angular js quick start
Angular js quick startAngular js quick start
Angular js quick start정기 김
 
Angular 기본 개념 잡기
Angular 기본 개념 잡기Angular 기본 개념 잡기
Angular 기본 개념 잡기장현 한
 
웹-프론트엔드 프레임워크를 고르기 위한 팁
웹-프론트엔드 프레임워크를 고르기 위한 팁웹-프론트엔드 프레임워크를 고르기 위한 팁
웹-프론트엔드 프레임워크를 고르기 위한 팁WebFrameworks
 
Universal Rendering
Universal RenderingUniversal Rendering
Universal RenderingTaegon Kim
 
Angularjs 도입 선택 가이드
Angularjs 도입 선택 가이드Angularjs 도입 선택 가이드
Angularjs 도입 선택 가이드NAVER D2
 
[114]angularvs react 김훈민손찬욱
[114]angularvs react 김훈민손찬욱[114]angularvs react 김훈민손찬욱
[114]angularvs react 김훈민손찬욱NAVER D2
 
Vue SSR vs Prerender
Vue SSR vs PrerenderVue SSR vs Prerender
Vue SSR vs PrerenderChangwan Jun
 
목적에 맞게 Angular, React, Vue
목적에 맞게 Angular, React, Vue목적에 맞게 Angular, React, Vue
목적에 맞게 Angular, React, VueGunhee Lee
 
Spring boot 5장 cli
Spring boot 5장 cliSpring boot 5장 cli
Spring boot 5장 cliChoonghyun Yang
 
스프링프레임워크 & 마이바티스 무.료 강의자료 제공 (Spring IoC & DI)_ 구로자바학원/구로오라클학원/구로IT학원
스프링프레임워크 & 마이바티스 무.료 강의자료 제공 (Spring IoC & DI)_ 구로자바학원/구로오라클학원/구로IT학원스프링프레임워크 & 마이바티스 무.료 강의자료 제공 (Spring IoC & DI)_ 구로자바학원/구로오라클학원/구로IT학원
스프링프레임워크 & 마이바티스 무.료 강의자료 제공 (Spring IoC & DI)_ 구로자바학원/구로오라클학원/구로IT학원탑크리에듀(구로디지털단지역3번출구 2분거리)
 
Spring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCodeSpring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCodedpTablo
 
[오픈소스컨설팅]Gradle Basic - How to use Gradle in Java Project
[오픈소스컨설팅]Gradle Basic - How to use Gradle in Java Project[오픈소스컨설팅]Gradle Basic - How to use Gradle in Java Project
[오픈소스컨설팅]Gradle Basic - How to use Gradle in Java ProjectJi-Woong Choi
 
Ionic으로 모바일앱 만들기 #2
Ionic으로 모바일앱 만들기 #2Ionic으로 모바일앱 만들기 #2
Ionic으로 모바일앱 만들기 #2성일 한
 
가볍게 살펴보는 AngularJS
가볍게 살펴보는 AngularJS가볍게 살펴보는 AngularJS
가볍게 살펴보는 AngularJSJae Sung Park
 

Was ist angesagt? (20)

Angular js quick start
Angular js quick startAngular js quick start
Angular js quick start
 
Angular 기본 개념 잡기
Angular 기본 개념 잡기Angular 기본 개념 잡기
Angular 기본 개념 잡기
 
웹-프론트엔드 프레임워크를 고르기 위한 팁
웹-프론트엔드 프레임워크를 고르기 위한 팁웹-프론트엔드 프레임워크를 고르기 위한 팁
웹-프론트엔드 프레임워크를 고르기 위한 팁
 
Universal Rendering
Universal RenderingUniversal Rendering
Universal Rendering
 
Angularjs 도입 선택 가이드
Angularjs 도입 선택 가이드Angularjs 도입 선택 가이드
Angularjs 도입 선택 가이드
 
[114]angularvs react 김훈민손찬욱
[114]angularvs react 김훈민손찬욱[114]angularvs react 김훈민손찬욱
[114]angularvs react 김훈민손찬욱
 
Vue SSR vs Prerender
Vue SSR vs PrerenderVue SSR vs Prerender
Vue SSR vs Prerender
 
3.Spring IoC&DI(spring ioc실습, XML기반)
3.Spring IoC&DI(spring ioc실습, XML기반)3.Spring IoC&DI(spring ioc실습, XML기반)
3.Spring IoC&DI(spring ioc실습, XML기반)
 
목적에 맞게 Angular, React, Vue
목적에 맞게 Angular, React, Vue목적에 맞게 Angular, React, Vue
목적에 맞게 Angular, React, Vue
 
1.스프링프레임워크 개요
1.스프링프레임워크 개요1.스프링프레임워크 개요
1.스프링프레임워크 개요
 
Springmvc
SpringmvcSpringmvc
Springmvc
 
Spring boot 5장 cli
Spring boot 5장 cliSpring boot 5장 cli
Spring boot 5장 cli
 
스프링프레임워크 & 마이바티스 무.료 강의자료 제공 (Spring IoC & DI)_ 구로자바학원/구로오라클학원/구로IT학원
스프링프레임워크 & 마이바티스 무.료 강의자료 제공 (Spring IoC & DI)_ 구로자바학원/구로오라클학원/구로IT학원스프링프레임워크 & 마이바티스 무.료 강의자료 제공 (Spring IoC & DI)_ 구로자바학원/구로오라클학원/구로IT학원
스프링프레임워크 & 마이바티스 무.료 강의자료 제공 (Spring IoC & DI)_ 구로자바학원/구로오라클학원/구로IT학원
 
Spring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCodeSpring Boot + React + Gradle in VSCode
Spring Boot + React + Gradle in VSCode
 
[오픈소스컨설팅]Gradle Basic - How to use Gradle in Java Project
[오픈소스컨설팅]Gradle Basic - How to use Gradle in Java Project[오픈소스컨설팅]Gradle Basic - How to use Gradle in Java Project
[오픈소스컨설팅]Gradle Basic - How to use Gradle in Java Project
 
Ionic으로 모바일앱 만들기 #2
Ionic으로 모바일앱 만들기 #2Ionic으로 모바일앱 만들기 #2
Ionic으로 모바일앱 만들기 #2
 
Spring boot
Spring bootSpring boot
Spring boot
 
가볍게 살펴보는 AngularJS
가볍게 살펴보는 AngularJS가볍게 살펴보는 AngularJS
가볍게 살펴보는 AngularJS
 
Spring boot DI
Spring boot DISpring boot DI
Spring boot DI
 
Modern PHP
Modern PHPModern PHP
Modern PHP
 

Andere mochten auch

신림프로그래머 스터디 웹팩 발표자료
신림프로그래머 스터디 웹팩 발표자료신림프로그래머 스터디 웹팩 발표자료
신림프로그래머 스터디 웹팩 발표자료라한사 아
 
ECMAScript 6의 새로운 것들!
ECMAScript 6의 새로운 것들!ECMAScript 6의 새로운 것들!
ECMAScript 6의 새로운 것들!WooYoung Cho
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0Jeado Ko
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Jeado Ko
 
Presentation
PresentationPresentation
Presentationncpepin
 
cancell this presentation.
cancell this presentation.cancell this presentation.
cancell this presentation.Andre Lemmer
 
Ti apresentation pepin
Ti apresentation pepinTi apresentation pepin
Ti apresentation pepinncpepin
 

Andere mochten auch (20)

신림프로그래머 스터디 웹팩 발표자료
신림프로그래머 스터디 웹팩 발표자료신림프로그래머 스터디 웹팩 발표자료
신림프로그래머 스터디 웹팩 발표자료
 
ECMAScript 6의 새로운 것들!
ECMAScript 6의 새로운 것들!ECMAScript 6의 새로운 것들!
ECMAScript 6의 새로운 것들!
 
준비하세요 Angular js 2.0
준비하세요 Angular js 2.0준비하세요 Angular js 2.0
준비하세요 Angular js 2.0
 
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
Angular를 활용한 웹 프론트단 개발과 2.0에서 달라진점
 
Smart Grid Analytics
Smart Grid AnalyticsSmart Grid Analytics
Smart Grid Analytics
 
Southern Thomson Project update
Southern Thomson Project updateSouthern Thomson Project update
Southern Thomson Project update
 
Лабораторная работа №4
Лабораторная работа №4Лабораторная работа №4
Лабораторная работа №4
 
Mte penyertaan
Mte penyertaanMte penyertaan
Mte penyertaan
 
Muscular system
Muscular systemMuscular system
Muscular system
 
Presentation
PresentationPresentation
Presentation
 
cancell this presentation.
cancell this presentation.cancell this presentation.
cancell this presentation.
 
Mte penyertaan
Mte penyertaanMte penyertaan
Mte penyertaan
 
Mte penghargaan
Mte penghargaanMte penghargaan
Mte penghargaan
 
Smart Grid, Smart City
Smart Grid, Smart City Smart Grid, Smart City
Smart Grid, Smart City
 
Ti apresentation pepin
Ti apresentation pepinTi apresentation pepin
Ti apresentation pepin
 
portfolio
portfolioportfolio
portfolio
 
FERMÁQUINAS
FERMÁQUINASFERMÁQUINAS
FERMÁQUINAS
 
Limbajultrupului(cOp)
Limbajultrupului(cOp)Limbajultrupului(cOp)
Limbajultrupului(cOp)
 
Deveco
DevecoDeveco
Deveco
 
Qalam w maidan final
Qalam w maidan final Qalam w maidan final
Qalam w maidan final
 

Ähnlich wie Angular 2 rc5 조사

Data-binding AngularJS
Data-binding AngularJSData-binding AngularJS
Data-binding AngularJSEunYoung Kim
 
백기선의 스프링 부트
백기선의 스프링 부트백기선의 스프링 부트
백기선의 스프링 부트Keesun Baik
 
막하는 스터디 네 번째 만남 AngularJs (20151108)
막하는 스터디 네 번째 만남 AngularJs (20151108)막하는 스터디 네 번째 만남 AngularJs (20151108)
막하는 스터디 네 번째 만남 AngularJs (20151108)연웅 조
 
LucideWorks Banana 소개
LucideWorks Banana 소개 LucideWorks Banana 소개
LucideWorks Banana 소개 SuHyun Jeon
 
앵귤러 첫걸음(Angular for beginers)
앵귤러 첫걸음(Angular for beginers)앵귤러 첫걸음(Angular for beginers)
앵귤러 첫걸음(Angular for beginers)양 한빛
 
Polymer따라잡기
Polymer따라잡기Polymer따라잡기
Polymer따라잡기Han Jung Hyun
 
다시보는 Angular js
다시보는 Angular js다시보는 Angular js
다시보는 Angular jsJeado Ko
 
Bug sense 분석
Bug sense 분석Bug sense 분석
Bug sense 분석logdog
 
04.실행환경 교육교재(화면처리)
04.실행환경 교육교재(화면처리)04.실행환경 교육교재(화면처리)
04.실행환경 교육교재(화면처리)Hankyo
 
[1A5]효율적인안드로이드앱개발
[1A5]효율적인안드로이드앱개발[1A5]효율적인안드로이드앱개발
[1A5]효율적인안드로이드앱개발NAVER D2
 
3D 모델러 ADDIN 개발과정 요약
3D 모델러 ADDIN 개발과정 요약3D 모델러 ADDIN 개발과정 요약
3D 모델러 ADDIN 개발과정 요약Tae wook kang
 
[React-Native-Seoul] React-Native 초심자를 위한 실습위주의 간단한 소개 및 구현법 안내
[React-Native-Seoul] React-Native 초심자를 위한 실습위주의 간단한 소개 및 구현법 안내[React-Native-Seoul] React-Native 초심자를 위한 실습위주의 간단한 소개 및 구현법 안내
[React-Native-Seoul] React-Native 초심자를 위한 실습위주의 간단한 소개 및 구현법 안내Tae-Seong Park
 
PHP Slim Framework with Angular
PHP Slim Framework with AngularPHP Slim Framework with Angular
PHP Slim Framework with AngularJT Jintae Jung
 
MVVM Pattern for Android
MVVM Pattern for AndroidMVVM Pattern for Android
MVVM Pattern for Androidtaeinkim6
 
자바스크립트 프레임워크 살펴보기
자바스크립트 프레임워크 살펴보기자바스크립트 프레임워크 살펴보기
자바스크립트 프레임워크 살펴보기Jeado Ko
 
Isomorphicspring Isomorphic - spring web seminar 2015
Isomorphicspring Isomorphic - spring web seminar 2015Isomorphicspring Isomorphic - spring web seminar 2015
Isomorphicspring Isomorphic - spring web seminar 2015sung yong jung
 
Angular js 의존관계 주입과 서비스
Angular js 의존관계 주입과 서비스Angular js 의존관계 주입과 서비스
Angular js 의존관계 주입과 서비스Tae Ho Kang
 
Catalyst Framework 살펴보기
Catalyst Framework 살펴보기Catalyst Framework 살펴보기
Catalyst Framework 살펴보기corund
 

Ähnlich wie Angular 2 rc5 조사 (20)

Data-binding AngularJS
Data-binding AngularJSData-binding AngularJS
Data-binding AngularJS
 
백기선의 스프링 부트
백기선의 스프링 부트백기선의 스프링 부트
백기선의 스프링 부트
 
막하는 스터디 네 번째 만남 AngularJs (20151108)
막하는 스터디 네 번째 만남 AngularJs (20151108)막하는 스터디 네 번째 만남 AngularJs (20151108)
막하는 스터디 네 번째 만남 AngularJs (20151108)
 
Nest js 101
Nest js 101Nest js 101
Nest js 101
 
LucideWorks Banana 소개
LucideWorks Banana 소개 LucideWorks Banana 소개
LucideWorks Banana 소개
 
앵귤러 첫걸음(Angular for beginers)
앵귤러 첫걸음(Angular for beginers)앵귤러 첫걸음(Angular for beginers)
앵귤러 첫걸음(Angular for beginers)
 
Polymer따라잡기
Polymer따라잡기Polymer따라잡기
Polymer따라잡기
 
다시보는 Angular js
다시보는 Angular js다시보는 Angular js
다시보는 Angular js
 
Bug sense 분석
Bug sense 분석Bug sense 분석
Bug sense 분석
 
04.실행환경 교육교재(화면처리)
04.실행환경 교육교재(화면처리)04.실행환경 교육교재(화면처리)
04.실행환경 교육교재(화면처리)
 
[1A5]효율적인안드로이드앱개발
[1A5]효율적인안드로이드앱개발[1A5]효율적인안드로이드앱개발
[1A5]효율적인안드로이드앱개발
 
3D 모델러 ADDIN 개발과정 요약
3D 모델러 ADDIN 개발과정 요약3D 모델러 ADDIN 개발과정 요약
3D 모델러 ADDIN 개발과정 요약
 
[React-Native-Seoul] React-Native 초심자를 위한 실습위주의 간단한 소개 및 구현법 안내
[React-Native-Seoul] React-Native 초심자를 위한 실습위주의 간단한 소개 및 구현법 안내[React-Native-Seoul] React-Native 초심자를 위한 실습위주의 간단한 소개 및 구현법 안내
[React-Native-Seoul] React-Native 초심자를 위한 실습위주의 간단한 소개 및 구현법 안내
 
PHP Slim Framework with Angular
PHP Slim Framework with AngularPHP Slim Framework with Angular
PHP Slim Framework with Angular
 
MVVM Pattern for Android
MVVM Pattern for AndroidMVVM Pattern for Android
MVVM Pattern for Android
 
자바스크립트 프레임워크 살펴보기
자바스크립트 프레임워크 살펴보기자바스크립트 프레임워크 살펴보기
자바스크립트 프레임워크 살펴보기
 
Isomorphicspring Isomorphic - spring web seminar 2015
Isomorphicspring Isomorphic - spring web seminar 2015Isomorphicspring Isomorphic - spring web seminar 2015
Isomorphicspring Isomorphic - spring web seminar 2015
 
react-ko.pdf
react-ko.pdfreact-ko.pdf
react-ko.pdf
 
Angular js 의존관계 주입과 서비스
Angular js 의존관계 주입과 서비스Angular js 의존관계 주입과 서비스
Angular js 의존관계 주입과 서비스
 
Catalyst Framework 살펴보기
Catalyst Framework 살펴보기Catalyst Framework 살펴보기
Catalyst Framework 살펴보기
 

Kürzlich hochgeladen

친환경, 그린, 탄소저감 미래 교육 공간 디자인의 이해와 사례들에 대한 강의 자료
친환경, 그린, 탄소저감  미래 교육 공간 디자인의 이해와 사례들에 대한 강의 자료친환경, 그린, 탄소저감  미래 교육 공간 디자인의 이해와 사례들에 대한 강의 자료
친환경, 그린, 탄소저감 미래 교육 공간 디자인의 이해와 사례들에 대한 강의 자료Seongwon Kim
 
TDM(Text Data Mining) Studio manual(2024)
TDM(Text Data Mining) Studio manual(2024)TDM(Text Data Mining) Studio manual(2024)
TDM(Text Data Mining) Studio manual(2024)yonseilibrary
 
코딩테스트 합격자 되기 C++ 03장(시간 복잡도)를 설명한 ppt입니다
코딩테스트 합격자 되기 C++ 03장(시간 복잡도)를 설명한 ppt입니다코딩테스트 합격자 되기 C++ 03장(시간 복잡도)를 설명한 ppt입니다
코딩테스트 합격자 되기 C++ 03장(시간 복잡도)를 설명한 ppt입니다ultrasuperrok
 
바리스타이론기초-1 수정 후 111111111111111111111111
바리스타이론기초-1 수정 후 111111111111111111111111바리스타이론기초-1 수정 후 111111111111111111111111
바리스타이론기초-1 수정 후 111111111111111111111111a01091282057
 
코딩 테스트 합격자 되기 C++ 00장~ 01장을 정리한 강의자료 입니다.
코딩 테스트 합격자 되기 C++ 00장~ 01장을 정리한 강의자료 입니다.코딩 테스트 합격자 되기 C++ 00장~ 01장을 정리한 강의자료 입니다.
코딩 테스트 합격자 되기 C++ 00장~ 01장을 정리한 강의자료 입니다.ultrasuperrok
 
이번에 새로 나온 코딩 테스트 합격자 되기 C++편 책을 소개하는 PPT 입니다.
이번에 새로 나온 코딩 테스트 합격자 되기 C++편 책을 소개하는 PPT 입니다.이번에 새로 나온 코딩 테스트 합격자 되기 C++편 책을 소개하는 PPT 입니다.
이번에 새로 나온 코딩 테스트 합격자 되기 C++편 책을 소개하는 PPT 입니다.ultrasuperrok
 

Kürzlich hochgeladen (6)

친환경, 그린, 탄소저감 미래 교육 공간 디자인의 이해와 사례들에 대한 강의 자료
친환경, 그린, 탄소저감  미래 교육 공간 디자인의 이해와 사례들에 대한 강의 자료친환경, 그린, 탄소저감  미래 교육 공간 디자인의 이해와 사례들에 대한 강의 자료
친환경, 그린, 탄소저감 미래 교육 공간 디자인의 이해와 사례들에 대한 강의 자료
 
TDM(Text Data Mining) Studio manual(2024)
TDM(Text Data Mining) Studio manual(2024)TDM(Text Data Mining) Studio manual(2024)
TDM(Text Data Mining) Studio manual(2024)
 
코딩테스트 합격자 되기 C++ 03장(시간 복잡도)를 설명한 ppt입니다
코딩테스트 합격자 되기 C++ 03장(시간 복잡도)를 설명한 ppt입니다코딩테스트 합격자 되기 C++ 03장(시간 복잡도)를 설명한 ppt입니다
코딩테스트 합격자 되기 C++ 03장(시간 복잡도)를 설명한 ppt입니다
 
바리스타이론기초-1 수정 후 111111111111111111111111
바리스타이론기초-1 수정 후 111111111111111111111111바리스타이론기초-1 수정 후 111111111111111111111111
바리스타이론기초-1 수정 후 111111111111111111111111
 
코딩 테스트 합격자 되기 C++ 00장~ 01장을 정리한 강의자료 입니다.
코딩 테스트 합격자 되기 C++ 00장~ 01장을 정리한 강의자료 입니다.코딩 테스트 합격자 되기 C++ 00장~ 01장을 정리한 강의자료 입니다.
코딩 테스트 합격자 되기 C++ 00장~ 01장을 정리한 강의자료 입니다.
 
이번에 새로 나온 코딩 테스트 합격자 되기 C++편 책을 소개하는 PPT 입니다.
이번에 새로 나온 코딩 테스트 합격자 되기 C++편 책을 소개하는 PPT 입니다.이번에 새로 나온 코딩 테스트 합격자 되기 C++편 책을 소개하는 PPT 입니다.
이번에 새로 나온 코딩 테스트 합격자 되기 C++편 책을 소개하는 PPT 입니다.
 

Angular 2 rc5 조사

  • 1. Angular 2 RC5 조사 by RYU (신림 프로그래머 모임)
  • 3. Angular 2를 감히 말하자면… • Angularjs2는 Javscript 및 Typescript, Dart와 같은 Javascript로 컴파일 되 는 언어로 Html안에서 Client Application을 만들기 위한 Framework • 몇 개의 코어와 몇 개의 부가적인 라이브러리로 구성 되어 있다. • Component 클래스를 이용하여 앵귤라화 된 Html 템플릿과 템플릿을 관리 하고, 컴포넌트를 관리하고 서비스의 로직을 추가 할 수 있다. • 최상위 모듈을 이용해 어플리케이션을 구동시킬 때 Angularjs는 브라우져에 어플리케이션을 출력하고 사용자에 행동에 따라 당신이 지정해 놓은 사용자 반응을 응답한다.
  • 5. Angular 2: 8가지 주요 요소 • Modules • Components • Templates • Metadata • Data binding • Directives • Services • Dependency injection
  • 6. Ionic Team이 소개하는 특징 • COMPONENT • INPUTS • OUTPUTS • APP LIFECYCLE • TEMPLATES • EVENTS • FORMS • VIEWCHILD
  • 7. # ANGULAR 2: COMPONENT 컴포넌트는 페이지에 로직과 페이지에 엘리먼트를 구체화할수 있는 주 요한 방법이다. 앵귤라1에서 directives, controllers, and scope를 통 해서 구현하였다면 앵귤러2 에서 해당 컨셉은 Components로 통합되 었다. import { Component } from '@angular/core'; @Component({ selector: 'my-app', template: '<h1>My First Angular 2 App</h1>' }) export class AppComponent { } import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppComponent } from './app.component'; import { OtherAppComponent } from './otherapp.component'; @NgModule({ imports: [ BrowserModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } import { platformBrowserDynamic } from '@angular/platform-browser- dynamic'; import { AppModule } from './app.module'; import { OtherAppModule } from './otherapp.module'; platformBrowserDynamic().boots trapModule(AppModule); platformBrowserDynamic().bootstra pModule(OtherAppModule);
  • 8. # ANGULAR 2: COMPONENT <html> <head> <title>Angular 2 QuickStart</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="styles.css"> <!-- 1. Load libraries --> <!-- Polyfill(s) for older browsers --> <script src="node_modules/core-js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.js"></script> <script src="node_modules/reflect-metadata/Reflect.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <!-- 2. Configure SystemJS --> <script src="systemjs.config.js"></script> <script> System.import('app').catch(function(err){ console.error(err); }); </script> </head> <!-- 3. Display the application --> <body> <my-app>Loading...</my-app> <other-my-app>Loading...</other-my-app> </body> </html> /** /** * System configuration for Angular 2 samples * Adjust as necessary for your application needs. */ (function(global) { // map tells the System loader where to look for things var map = { 'app': 'app', // 'dist', '@angular': 'node_modules/@angular', 'angular2-in-memory-web-api': 'node_modules/angular2-in-memory- web-api', 'rxjs': 'node_modules/rxjs' }; // packages tells the System loader how to load when no filename and/or no extension var packages = { 'app': { main: 'main.js', defaultExtension: 'js' }, 'rxjs': { defaultExtension: 'js' }, 'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }, }; var ngPackageNames = [ 'common', 'compiler', 'core', 'forms', 'http', 'platform-browser', 'platform-browser-dynamic', 'router', 'router-deprecated', 'upgrade', ]; // Individual files (~300 requests): function packIndex(pkgName) { packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' }; } // Bundled (~40 requests): function packUmd(pkgName) { packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' }; } // Most environments should use UMD; some (Karma) need the individual index files var setPackageConfig = System.packageWithIndex ? packIndex : packUmd; // Add package entries for angular packages ngPackageNames.forEach(setPackageConfig); var config = { map: map, packages: packages }; System.config(config); })(this);
  • 9. # ANGULAR 2: INPUTS 앵귤러 2 어플리케이션에서 코어는 컴포턴트들이긴 하지만 대부분 개 발자들은 동적으로 설정하여 컴포넌트에 어떻게 데이터를 넣어줄지 필 요할것이다. (컴포넌트 동적 프로퍼티 변경) @Input 컴포넌트에 'input'을 정의하기 위해서 '@Input'표시자를 써야 한다 . import { Component, Input } from '@angular/core'; @Component({ selector: 'my-number', template: '<div><p> The next number is {{ mynumber + 1}} </p></div>' }) export class MyNumberComponent { @Input() mynumber: number; } @Component({ selector: 'MyNumberRootComponent', directives: [MyNumberComponent], template: `<my-number [mynumber]="42"></my-number>` }) export class MyNumberRootComponent {}
  • 10. # ANGULAR 2: OUTPUTS 특별한 이벤트를 바인딩 할때 앵귤러 2에서는 이벤트 문법을 사용하여 처리 할 수 있지만. 필요한 커스텀 이벤트를 작성할때 @Output 지시자 를 사용하면 된다. ( 이벤트 동적 바인딩 ) import { Component, Output, EventEmitter } from '@angular/core'; @Component({ selector: 'zippy', template: ` <div class="zippy"> <button (click)="toggle()">눌러봐 ~</button> <div [hidden]="!visible">@Output 데코레이터를 통한 이벤트 동적 바인딩 </div> </div>` }) export class Zippy { visible: boolean = true; @Output() open: EventEmitter<any> = new EventEmitter(); @Output() close: EventEmitter<any> = new EventEmitter(); toggle() { this.visible = !this.visible; if (this.visible) { this.open.emit(null); } else { this.close.emit(null); } }
  • 11. # ANGULAR 2: APP LIFECYCLE ANGULAR는 다단계에 걸친 기동과 lifecycle 과정을 통해 시작되며 어플리케이 션이 시작/동작 컴포넌트의 생성과 소멸 될 때 다양한 이벤트를 받을 수 있다. BOOTSTRAP Angular 2 어플리케이션들은 the root component를 통해 기동된다. COMPONENT INIT 컴포넌트가 생성될때 그것에 생성자는 호출된다. 이것은 우리에 컴포넌트를 위한 초기화 영역이다. 그 러나 자식 컴포넌트부터 데이터나 속성에 의존되어 있다면 자식 컴포넌트가 먼저 초기화 하는 것을 기다려야 한다. 컴포넌트는 설정이나 어플리케이션 코드에 들어갈수 있다 컴포넌트들의 템플릿들은 전체 어플리 케이션에 연결이 생성 되는 곳에 있다. 'ngOnInit' lifecycle event을 통해서 이런 부분을 컨트롤 할수 있고 추가적 으로 setTimeout에서 호출하면서 생성자와 비슷한 효과를낼수 있다. COMPONENT LIFECYCLE 'ngOnInit' 같이 우리는 컴포넌트에 lifecycle 을 통해 몇가지 이벤트를 추적 할수 있다.
  • 12. # ANGULAR 2: APP LIFECYCLE import { Component } from '@angular/core'; @Component({ selector: ‘app-lifecycle', template: ` <div class="lifecycle">해당 컴포넌트 호출시 일어나는 이벤트 </div>` }) export class Zippy { ngOnInit() { console.log("call ngOnInit in Zippy Component"); // Properties are resolved and things like // this.mapWindow and this.mapControls // had a chance to resolve from the // two child components <map-window> and <map- controls> } ngOnDestroy() { console.log("call ngOnDestroy in Zippy Component"); // Speak now or forever hold your peace } ngDoCheck() { console.log("call ngDoCheck in Zippy Component"); // Custom change detection } ngOnChanges(changes) { console.log("call ngOnChanges in Zippy Component"); // Called right after our bindings have been checked but only // if one of our bindings has changed. // // changes is an object of the format: // { // 'prop': PropertyUpdate // } } ngAfterContentInit() { console.log("call ngAfterContentInit in Zippy Component"); // Component content has been initialized } ngAfterContentChecked() { console.log("call ngAfterContentChecked in Zippy Component"); // Component content has been Checked } ngAfterViewInit() { console.log("call ngAfterViewInit in Zippy Component"); // Component views are initialized } ngAfterViewChecked() { console.log("call ngAfterViewChecked in Zippy Component"); // Component views have been checked } …
  • 13. # ANGULAR 2: TEMPLATES 템플릿은 좀더 명확하게 작지만 많은 문법 변화가 일어났지만 앵귤라1 과 아주 흡사하다 - {}: RENDERING standard double-curly syntax 값을 출력한다. - []: BINDING PROPERTIES component에 변수를 맵핑 하기 위해서 '[]' 문법을 사용한다. 만약 우리에 컴포턴트에 this.currentVolume 값이 있을 때, 컴토넌트를 통해서 값을 넘겨주고 값들이 계속 동기화된다. - (): HANDLING EVENTS '()' 신텍스를 통해서 이벤트를 컴포넌트에서 처리할수 있다. - [()]: TWO-WAY DATA BINDING 다른 이벤트나 사용자의 입력을 통해서 변경을 유지하기 위해 '[()]' 문법을 사용하고 property를 연결하거나 이벤트처리에 대한 조합을 생각할수 있다. - *: THE ASTERISK '*'는 template로써 directive가 component를 다룰수 있는 것을 말한다. 전처럼 그리지는 않는다. 예를 들어 'ngFor'는 <my-component> 를 취해서 아이템리스트를 출력한다. 그러나 초기화는 하지 않는다. 몇몇 비슷한 다른 directives는 template에서 *ngIf, *ngSwitch보다 더 좋게 동작한다.
  • 14. # ANGULAR 2: TEMPLATES <div> Hello my name is {{name}} and I like {{thing}} quite a lot. </div> <video-control [volume]="currentVolume"></video-control> <my-component (click)="onClick($event)"></my-component> <input [(ngModel)]="myName"> <my-component *ngFor="#item of items"> </my-component> {}: RENDERING []: BINDING PROPERTIES (): HANDLING EVENTS [()]: TWO-WAY DATA BINDING *: THE ASTERISK
  • 15. # ANGULAR 2: EVENTS Angular2 에서의 이벤트는 템플릿 안에서 괄호 표현식을 사용하며 컴포턴트 클래스 안에 메소드와 연결되어 있다. DELEGATION (위임) Angular2 에서의 이벤트는 일반적인 DOM이벤트와 비슷하게 동작한다. 이벤트를 상향으 로 올리거나 아래로 전파할 수 있으며 특별한게 없다. EVENT OBJECT 이벤트를 처리 할 때 '$event'라는 파라메터로 템플릿에 이벤트 콜백(함수)로 처리한다.
  • 16. # ANGULAR 2: EVENTS import { Component } from '@angular/core'; @Component({ selector: 'keyup-event1', template: `<input (keyup)="onKey($event)"/><p>{{value}}</p>` }) export class KeyUpComponent_v1 { value = ''; onKey(event: KeyboardEvent){ this.value += (<HTMLInputElement>event.target).value + '|'; } } <html> <head> <title>Angular 2 Components Simple Example</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="styles.css"> <!-- 1. Load libraries --> <!-- Polyfill(s) for older browsers --> <script src="node_modules/core- js/client/shim.min.js"></script> <script src="node_modules/zone.js/dist/zone.js"></script> <script src="node_modules/reflect- metadata/Reflect.js"></script> <script src="node_modules/systemjs/dist/system.src.js"></script> <!-- 2. Configure SystemJS --> <script src="componentexample.config.js"></script> <script> System.import('app').catch(function(err){ console.error(err); }); </script> </head> <!-- 3. Display the application --> <body> <click-component>Loading...</click-component> <keyup-event1>Loading...</keyup-event1> </body> </html> import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { ClickComponent } from './componentexample.component'; import { KeyUpComponent_v1 } from './keyupevent.component'; @NgModule({ imports: [ BrowserModule ], declarations: [ ClickComponent, KeyUpComponent_v1 ], bootstrap: [ ClickComponent,KeyUpComponent_v1 ] }) export class ComponentExampleModule { }
  • 17. # ANGULAR 2: FORMS SIMPLE FORM FORMBUILDER The FormBuilder from the example above makes it easy for us to specify form controls and the various validators we might want to apply to certain controls. In the example above, we are creating two inputs, an email and password field: CONTROLGROUP The FormBuilder creates instances of ControlGroup, which we refer to as a form. Instead of using the FormBuilder, we could also construct the ControlGroup manually: In practice though, the FormBuilder is what we will use to quickly create forms. FORM DIRECTIVES You’ll notice the lack of ngModel anywhere in our form. Instead, we have the ngControl decorators that map certain inputs to our control objects: This “binds” the email input to the instance of our email control. CUSTOM VALIDATORS We can build custom form validators as a simple function: HANDLING FORM We can easily get the simple Javascript object value of our form, or the value of an individual control:
  • 18. # ANGULAR 2: VIEWCHILD ANGULAR 2에서 모든 컴포넌트들이 클래스를 가지기 떄문 에 클래스 안에 메소드를 호출한다. 이것으로 인해 컴포넌 트에 접근할수 있다. (쉽게 말해서 컴포넌트에서 컴포넌트 접근) @ViewChild Component과 그 것들의 method들을 접근하기 위해 @ViewChild 어노테이션을 쓸수 있다. 예를 들어 <user-profile> component가 sendData()라는 메소드를 호출 가능하다면 우리에 페이지에서 user-profile 를 사용할 때 클래스에 참조가능하며 지역 변수로 그것을 할당 가능하다.
  • 19. # ANGULAR 2: VIEWCHILD @Component({ selector: 'user-profile' }) export class UserProfile { sendData(){ //send data } } import { Component, ViewChild } from '@angular/core'; import { UserProfile } from '../user-profile'; @Component({ template: '<user-profile (click)="update()"></user-profile>', directives: [UserProfile] }) export class MasterPage { @ViewChild(UserProfile) userProfile: UserProfile update(){ this.userProfile.sendData(); } }