μλ νμΈμ, μ λ Angular 5μμ μ΄ λΌμ΄λΈλ¬λ¦¬λ₯Ό μλνμ§λ§ μλνμ§ μλ κ² κ°μ΅λλ€. λλ κ·Έλ° κ΅¬μ± μμ ν νλ¦Ώμ κ°μ§κ³ μμ΅λλ€
<a class="card clickable" [routerLink]="[product.id]">
<div class="card-img">
<img [lazyLoad]="product.logoUrl">
</div>
<div class="card-block">
<span class="card-media-title">{{product.name}}</span>
<div class="product-version">{{product.version}}</div>
<div class="product-release-date">{{product.releaseDate}}</div>
</div>
</a>
κ·Έλ¦¬κ³ κ·Έλ° κ΅¬μ± μμ
import {Component, Input} from '@angular/core';
import {Product} from '../products.state';
@Component({
selector: 'app-product-card',
templateUrl: './product-card.component.html',
styleUrls: ['./product-card.component.scss']
})
export class ProductCardComponent {
@Input() product: Product;
constructor() {
}
}
κ·Έλ¦¬κ³ λ΄ λͺ¨λ
import {NgModule} from '@angular/core';
import {CommonModule} from '@angular/common';
import {LazyLoadImageModule} from 'ng-lazyload-image';
import {ProductsComponent} from './products.component';
import {ProductsEpic} from './products.epic';
import {ProductsListComponent} from './products-list/products-list.component';
import {ProductCardComponent} from './product-card/product-card.component';
import {ProductsService} from './products.service';
import {ProductsActions} from './products.actions';
import {ProductsEmptyComponent} from './products-empty/products-empty.component';
import {CoreModule} from '../core/core.module';
import {BannerComponent} from './banner/banner.component';
import {RouterModule} from '@angular/router';
@NgModule({
imports: [
CommonModule,
RouterModule,
CoreModule,
LazyLoadImageModule
],
declarations: [
ProductsComponent,
ProductsListComponent,
ProductCardComponent,
ProductsEmptyComponent,
BannerComponent
],
providers: [
ProductsService,
ProductsEpic,
ProductsActions
]
})
export class ProductsModule {
}
μ΄λ―Έμ§λ μ λ λνλμ§ μμ΅λλ€. μ½μμμλ μ΄ κ²½κ³ λ©μμ§κ° λνλ©λλ€.
λ΄κ° λ μλͺ»νκ³ μλμ§ νμ€νμ§ μμ΅λλ€. λμμ μ£Όμλ©΄ κ°μ¬νκ² μ΅λλ€.
μλ νμΈμ @el-davoλ,
μ κ³ ν΄ μ£Όμ μ κ°μ¬ν©λλ€. μλ² λ λλ§μ μ¬μ©νκ³ μμ΅λκΉ? μλλ©΄ μ±μ 미리 μ»΄νμΌνμκ² μ΅λκΉ? μλλ©΄ κ°λ° λͺ¨λμμ μ±μ μ€ννκ³ μμ΅λκΉ?
μλ . μλμ, μλ² μΈ‘ λ λλ§μ μννμ§ μμ΅λλ€. μ, νμ¬ angular-cliλ₯Ό μ¬μ©νμ¬ κ°λ° λͺ¨λμ μμ΅λλ€.
μ΄λ€ λΈλΌμ°μ λ₯Ό μ¬μ©νκ³ μμ΅λκΉ?
λ°©κΈ cli(Angular 5)λ₯Ό μ¬μ©νμ¬ μ Angular μ±μ λ§λ€μκ³ μ΄λ₯Ό μ¬νν μ μμμ΅λλ€. λ€μκ³Ό κ°μ΄ λ³κ²½νμ΅λλ€.
diff --git a/src/app/app.component.html b/src/app/app.component.html
index 46d517b..215f0c9 100644
--- a/src/app/app.component.html
+++ b/src/app/app.component.html
@@ -6,15 +6,21 @@
<img width="300" src="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAyNTAgMjUwIj4KICAgIDxwYXRoIGZpbGw9IiNERDAwMzEiIGQ9Ik0xMjUgMzBMMzEuOSA2My4ybDE0LjIgMTIzLjFMMTI1IDIzMGw3OC45LTQzLjcgMTQuMi0xMjMuMXoiIC8+CiAgICA8cGF0aCBmaWxsPSIjQzMwMDJGIiBkPSJNMTI1IDMwdjIyLjItLjFWMjMwbDc4LjktNDMuNyAxNC4yLTEyMy4xTDEyNSAzMHoiIC8+CiAgICA8cGF0aCAgZmlsbD0iI0ZGRkZGRiIgZD0iTTEyNSA1Mi4xTDY2LjggMTgyLjZoMjEuN2wxMS43LTI5LjJoNDkuNGwxMS43IDI5LjJIMTgzTDEyNSA1Mi4xem0xNyA4My4zaC0zNGwxNy00MC45IDE3IDQwLjl6IiAvPgogIDwvc3ZnPg==">
</div>
<h2>Here are some links to help you start: </h2>
+<img [defaultImage]="defaultImage" [lazyLoad]="image">
<ul>
<li>
<h2><a target="_blank" rel="noopener" href="https://angular.io/tutorial">Tour of Heroes</a></h2>
diff --git a/src/app/app.component.ts b/src/app/app.component.ts
index 7b0f672..cf8cead 100644
--- a/src/app/app.component.ts
+++ b/src/app/app.component.ts
@@ -7,4 +7,6 @@ import { Component } from '@angular/core';
})
export class AppComponent {
title = 'app';
+ defaultImage = 'https://www.placecage.com/1000/1000';
+ image = 'https://images.unsplash.com/photo-1443890923422-7819ed4101c0?fm=jpg';
}
diff --git a/src/app/app.module.ts b/src/app/app.module.ts
index 926975a..7fb6d9d 100644
--- a/src/app/app.module.ts
+++ b/src/app/app.module.ts
@@ -1,18 +1,13 @@
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
+import { LazyLoadImageModule } from 'ng-lazyload-image';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
+ LazyLoadImageModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
plnkr(https://embed.plnkr.co/rr046QU9YYWALdX7Xzf6/)λ λ§λ€μμ§λ§ μ€λ₯λ₯Ό μ¬νν μ μμ΅λλ€.
μ€λ₯λ₯Ό μ¬ννκΈ° μν΄ μμ git repo λλ plnkrμ λ§λ€ μ μλ€κ³ μκ°νμλκΉ?
μ£μ‘ν©λλ€. λ΄ λ¬Έμ λ₯Ό μμΈν μ΄ν΄λ³΄λ λΈλΌμ°μ μμ λͺ¨λ μ€ν¬λ‘€ μ΄λ²€νΈλ₯Ό λΉνμ±ννλ κ²μ²λΌ 보μ΄λ μ΄ CSS μ‘°κ°μ΄ μλ κ²μΌλ‘ λνλ¬μ΅λλ€.
html, body {
overflow-x: hidden;
}
μ΄ λ¬Έμ λ₯Ό ν΄κ²°νκΈ° μν΄ λ€μκ³Ό κ°μ΄ μ¬μ©μ μ§μ μ€ν¬λ‘€ μ΄λ²€νΈλ₯Ό μΆκ°νμ΅λλ€.
import {Component, Input} from '@angular/core';
import {Product} from '../products.state';
import {Observable} from 'rxjs/Observable';
@Component({
selector: 'app-product-card',
templateUrl: './product-card.component.html',
styleUrls: ['./product-card.component.scss']
})
export class ProductCardComponent {
@Input() product: Product;
scrollObservable = Observable.fromEvent(document.body, 'scroll');
constructor() {
}
}
κ·Έλ¦¬κ³ λ΄ ν νλ¦Ώμμ
<a class="card clickable" [routerLink]="[product.id]">
<div class="card-img">
<img [lazyLoad]="product.logoUrl" [scrollObservable]="scrollObservable">
</div>
<div class="card-block">
<span class="card-media-title">{{product.name}}</span>
<div class="product-version">{{product.version}}</div>
<div class="product-release-date">{{product.releaseDate}}</div>
</div>
</a>
μ΄μ Angular 5μμ μλ²½νκ² μλν©λλ€.
κ°μ₯ μ μ©ν λκΈ
μ£μ‘ν©λλ€. λ΄ λ¬Έμ λ₯Ό μμΈν μ΄ν΄λ³΄λ λΈλΌμ°μ μμ λͺ¨λ μ€ν¬λ‘€ μ΄λ²€νΈλ₯Ό λΉνμ±ννλ κ²μ²λΌ 보μ΄λ μ΄ CSS μ‘°κ°μ΄ μλ κ²μΌλ‘ λνλ¬μ΅λλ€.
μ΄ λ¬Έμ λ₯Ό ν΄κ²°νκΈ° μν΄ λ€μκ³Ό κ°μ΄ μ¬μ©μ μ§μ μ€ν¬λ‘€ μ΄λ²€νΈλ₯Ό μΆκ°νμ΅λλ€.
κ·Έλ¦¬κ³ λ΄ ν νλ¦Ώμμ
μ΄μ Angular 5μμ μλ²½νκ² μλν©λλ€.