Woongjae Lee
Daangn - Frontend Core Team ex) NHN Dooray - Frontend Team Leader ex) ProtoPie - Studio Team
2woongjae@gmail.com
{
...,
"dependencies": {
"@angular/animations": "^5.0.0",
"@angular/common": "^5.0.0",
"@angular/compiler": "^5.0.0",
"@angular/core": "^5.0.0",
"@angular/forms": "^5.0.0",
"@angular/http": "^5.0.0",
"@angular/platform-browser": "^5.0.0",
"@angular/platform-browser-dynamic": "^5.0.0",
"@angular/router": "^5.0.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.2",
"zone.js": "^0.8.14"
},
...
}import { BrowserModule } from '@angular/platform-browser';
import { NgModule, Routes } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
const routes: Routes = [
{path: '', component: HomeComponent},
{path: 'about', component: AboutComponent}
];
@NgModule({
declarations: [
AppComponent,
HomeComponent,
AboutComponent
],
imports: [
BrowserModule,
RouterModule.forRoot(routes)
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }<div style="text-align:center">
<h1>
Welcome to {{ title }}!
</h1>
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<router-outlet></router-outlet>import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
import { RouterModule, Routes } from '@angular/router';
const routes: Routes = [
{path: '', component: HomeComponent},
{path: 'about', component: AboutComponent}
];
export default RouterModule.forRoot(routes);import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import appRoutes from './app.routes';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
AboutComponent
],
imports: [
BrowserModule,
appRoutes
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }<nav>
<a routerLink="" routerLinkActive="active" [routerLinkActiveOptions]="{exact: true}">Home</a>
<a routerLink="about" routerLinkActive="active">About</a>
<a routerLink="developer" routerLinkActive="active">Developer</a>
</nav>
<router-outlet></router-outlet>a.active {
color: green;
font-weight: bold;
}import { RouterModule, Routes } from '@angular/router';
import { HomeComponent } from './home/home.component';
import { AboutComponent } from './about/about.component';
import { DeveloperComponent } from './developer/developer.component';
const routes: Routes = [
{path: '', component: HomeComponent},
{path: 'about', component: AboutComponent},
{path: 'developer', component: DeveloperComponent},
{path: 'developer/:name', component: DeveloperComponent}
];
export default RouterModule.forRoot(routes);import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
@Component({
selector: 'app-developer',
templateUrl: './developer.component.html',
styleUrls: ['./developer.component.css']
})
export class DeveloperComponent implements OnInit {
name;
constructor(private route: ActivatedRoute) {
console.log(route.snapshot.paramMap.get('name'));
this.name = route.snapshot.paramMap.get('name');
}
ngOnInit() {
}
}import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import 'rxjs/add/operator/map';
@Component({
selector: 'app-developer',
templateUrl: './developer.component.html',
styleUrls: ['./developer.component.css']
})
export class DeveloperComponent implements OnInit {
name;
constructor(private route: ActivatedRoute) {
this.name = route.params.map(p => p.name);
}
ngOnInit() {
}
}
/*
템플릿
{{ name | async }}
*/class EnginService {
public start(): void {
console.log('엔진 스타트');
}
}
class WheelService {
public start(): void {
console.log('바퀴 스타트');
}
}
class CarComponent {
private _engine = new EnginService();
private _wheel = new WheelService();
constructor() {
}
public start(): void {
this._engine.start();
this._wheel.start();
}
}
const car = new CarComponent();
car.start();import { Injectable } from '@angular/core';
@Injectable()
export class LogService {
private _count = 0;
constructor() { }
public info(message: string): void {
console.log('info', message, this._count);
this._count++;
}
}
import { Component, OnInit } from '@angular/core';
import { LogService } from '../log.service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
providers: [LogService]
})
export class HomeComponent implements OnInit {
constructor(private logService: LogService) { }
ngOnInit() {
this.logService.info('집에서 로그 서비스 사용');
}
}
import { Component, OnInit } from '@angular/core';
import { LogService } from '../log.service';
@Component({
selector: 'app-company',
templateUrl: './company.component.html',
styleUrls: ['./company.component.css'],
providers: [LogService]
})
export class CompanyComponent implements OnInit {
constructor(private logService: LogService) { }
ngOnInit() {
this.logService.info('회사에서 로그 서비스 사용');
}
}
<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
<h1>
Welcome to {{ title }}!
</h1>
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<app-home></app-home>
<app-company></app-company>import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { CompanyComponent } from './company/company.component';
import { LogService } from './log.service';
@NgModule({
declarations: [
AppComponent,
HomeComponent,
CompanyComponent
],
imports: [
BrowserModule
],
providers: [LogService],
bootstrap: [AppComponent]
})
export class AppModule { }import { Component, OnInit, Inject } from '@angular/core';
import { LogService } from '../log.service';
import { FactoryService } from '../factory.service';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
providers: [
LogService,
{
provide: 'githubUrl',
useValue: 'https://github.com'
},
{
provide: 'log',
useExisting: LogService
},
{
provide: 'factory',
useFactory: (logService) => {
return new FactoryService(logService, true);
},
deps: [LogService]
}
]
})
export class HomeComponent implements OnInit {
constructor(
@Inject('githubUrl') private githubUrl,
@Inject('log') private logService,
@Inject('factory') private factoryService
) { }
ngOnInit() {
console.log(this.githubUrl);
this.logService.info('안녕하세요');
this.factoryService.log();
}
}
import { Injectable } from '@angular/core';
@Injectable()
export class LogService {
constructor() { }
public info(message: string): void {
console.log('info', message);
}
}
import { Injectable } from '@angular/core';
import { LogService } from './log.service';
@Injectable()
export class FactoryService {
constructor(private logService: LogService, private isFactory: boolean) { }
public log(): void {
this.logService.info(`factory: ${this.isFactory}`);
}
}
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { HomeComponent } from './home/home.component';
import { HttpModule } from '@angular/http';
@NgModule({
declarations: [
AppComponent,
HomeComponent
],
imports: [
BrowserModule,
HttpModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import { Component, OnInit, Inject } from '@angular/core';
import { LogService } from '../log.service';
import { FactoryService } from '../factory.service';
import { Http } from '@angular/http';
@Component({
selector: 'app-home',
templateUrl: './home.component.html',
styleUrls: ['./home.component.css'],
providers: [
LogService,
{
provide: 'githubUrl',
useValue: 'https://api.github.com/users'
},
{
provide: 'log',
useExisting: LogService
},
{
provide: 'factory',
useFactory: (logService) => {
return new FactoryService(logService, true);
},
deps: [LogService]
}
]
})
export class HomeComponent implements OnInit {
data = [];
constructor(
@Inject('githubUrl') private githubUrl,
@Inject('log') private logService,
@Inject('factory') private factoryService,
private http: Http
) { }
ngOnInit() {
this.logService.info(this.githubUrl);
this.factoryService.log();
this.http.get(this.githubUrl)
.toPromise()
.then(data => {
this.data = data.json();
})
.catch(err => {
console.log(err);
this.data = [];
});
}
}<!--The content below is only a placeholder and can be replaced.-->
<div style="text-align:center">
<h1>
Welcome to {{ title }}!
</h1>
<img width="300" alt="Angular Logo" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<h2 *ngIf="isVisible">Here are some links to help you start: </h2>
<ul>
<li *ngFor="let item of list">
<h2><a target="_blank" rel="noopener" [href]="item.url">{{ item.title }}</a></h2>
</li>
</ul>
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
isVisible = false;
list = [
{url: 'https://angular.io/tutorial', title: 'Tour of Heroes'},
{url: 'https://github.com/angular/angular-cli/wiki', title: 'CLI Documentation'},
{url: 'https://blog.angular.io/', title: 'Angular blog'}
];
}
<p>{{ {'name': 'mark'} | json }}</p>
<p>{{ 'markzzang' | slice:0:4 }}</p>
<p>{{ ['mark', 'anna'] | slice:0:1 }}</p>
<p>{{ 'mark' | uppercase }}</p>
<p>{{ 'Mark' | lowercase }}</p>
<p>{{ 'mark' | uppercase | lowercase }}</p>
<p>{{ 1234566789012 | date:'yyyy-MM-dd' }}</p>
<!-- <p>{{ data | async }}</p> -->By Woongjae Lee
코드버스킹 Angular 101 - 두번째
Daangn - Frontend Core Team ex) NHN Dooray - Frontend Team Leader ex) ProtoPie - Studio Team