๋ค์์ ๊ฐ๋ก ์คํฌ๋กค์์ ์ด๋ฏธ์ง๋ฅผ ๋ก๋ํ์ง ์์ต๋๋ค.
<ion-scroll scrollX="true" #lazyContainer>
<!--<img class="thumbnail-avatar" *ngFor="let item of items" src="http://placehold.it/350x150">-->
<img class="thumbnail-avatar-square spacer" *ngFor="let item of recent"
(click)="tapped(item)"
[scrollObservable]="lazyContainer.ionScroll"
[lazyLoad]="item.avatar">
</ion-scroll>
์๋ ,
lazyContainer.ionScroll
๋ ์ด๋ค ์ด์ ๋ก ์ธ๋ก๋ก ์คํฌ๋กคํ ๋๋ง ์ด๋ฒคํธ๋ฅผ ๋ฐ์์ํค๋ ๊ฒ ๊ฐ์ต๋๋ค. ionScroll
๊ฐ์ ์ธ์ํ์ฌ ์คํฌ๋กคํ ๋ ๊ฐ์ด ๋ฐฉ์ถ๋๋์ง ํ์ธํ ์ ์์ต๋๊น?
<ion-scroll scrollX="true" #lazyContainer>
<img class="thumbnail-avatar-square spacer" *ngFor="let item of recent"
(click)="tapped(item)"
[scrollObservable]="lazyContainer.ionScroll"
[lazyLoad]="item.avatar">
{{ lazyContainer.ionScroll | async | json }}
</ion-scroll>
@kodeine ๋ฌธ์ ๊ฐ ๊ณ์ ๋ฐ์ํ๋ฉด ์ด ๋ฌธ์ ๋ฅผ ๋ค์ ์ฌ์ญ์์ค.
์๋ ํ์ธ์,
๋จผ์ ... @tjoskar ์ถํํฉ๋๋ค. ์ด๊ฒ์ Ionic 3.9.2์์ ์์๋๋ก ์๋ํฉ๋๋ค. ๊ทธ๋ฌ๋ ์ด์จ ์คํฌ๋กค๊ณผ ๋์ผํ ๋ฌธ์ ๊ฐ ์์ต๋๋ค. ๋ฐฉ๊ธ async/json ํ์ดํ๋ฅผ ์ฌ์ฉํ์ฌ ionScroll์ ๊ฐ์ ์ธ์ํ๋ ค๊ณ ์๋ํ๋๋ฐ null์ ๋ฐํํฉ๋๋ค. ๊ทธ๋์ ๊ทธ๊ฒ์ด ์๋ํ์ง ์๋ ์ด์ ๋ผ๊ณ ์๊ฐํฉ๋๋ค.
์ด ์ด์จ ๋ฌธ์ ์ ๋ํ ํด๊ฒฐ ๋ฐฉ๋ฒ์ด ์์ต๋๊น?
์ ๋ฐ์ดํธ: ๋๋ ์์ ์์ ์ ๋์ผํ ๊ฒ์ ์๋ํ๊ณ ๋ํ ionScroll์ด null์ ๋ฐํํ๊ณ ์์ต๋๊น?
์๋ํฉ๋๋ค. ํต์ฌ์ scrollTarget์ scroll._scrollContent.nativeElement
์๋ ์ ์ฒด ์ฝ๋
`` javascript
<ion-scroll scrollX="true" direction="x" #scroll1>
<div class="item" margin *ngFor="let item of newItems"
(click)="goToItemPage(item)">
<img src="./assets/imgs/placeholder.png"
[lazyLoad]="item.photoThumb?.url()"
[scrollTarget]="scroll1._scrollContent.nativeElement" />
<div text-center text-wrap>
<p no-margin>{{ (item.shortName || item.name) | excerpt:17 }}</p>
</div>
</div>
</ion-scroll>
์๋
ํ์ธ์ @fmendoza ๊ฐ ํ์ด ๊ฐ๋ก๋ก ์คํฌ๋กค ๊ฐ๋ฅํ๊ณ ์ด๋ฏธ์ง๋ฅผ ์ง์ฐ ๋ก๋ํด์ผ ํ๋ ์ฌ๋ฌ ํ์ด ์์ต๋๋ค.
๊ทธ๋ฌ๋ ์ฒซ ๋ฒ์งธ ๋ก๋ ์ ๋ณด์ด๋ ํ๋ง ์ด๋ฏธ์ง๋ฅผ ํ์ํฉ๋๋ค.
์์ง์ผ๋ก ์คํฌ๋กคํ์ฌ ๋ค๋ฅธ ํ์ ๋
ธ์ถํด๋ ์ด๋ฏธ์ง ๋ก๋๊ฐ ํธ๋ฆฌ๊ฑฐ๋์ง ์์ต๋๋ค.
๋ด ์ด์จ ์ฝํ
์ธ ์ ์์ง ์คํฌ๋กค๊ณผ ๋ด ์ด์จ ์คํฌ๋กค์ ์ํ ์คํฌ๋กค์์ ์ด๋ฌํ ์ด๋ฏธ์ง๋ฅผ ๋ก๋ํ๊ณ ์ถ์ต๋๋ค.
๋ ๊ฐ์ scrollTargets์ ํจ๊ป ์๋ํ๋๋ก ํฉ๋๋ค. ํ๋๋ ์ด์จ ์คํฌ๋กค์ฉ์ด๊ณ ๋ค๋ฅธ ํ๋๋ ์ด์จ ํจ๋์ฉ์
๋๋ค.
์น์ ํ๊ฒ ๋์์ฃผ์ธ์
์ ๋ ์๋ ํดํน์ ์ฌ์ฉํ์ฌ ์ํ์ผ๋ก ์คํฌ๋กค๋ ๋ชฉ๋ก์ด ๊ธฐ๋ณธ ์ฝํ
์ธ ์ ์์ง ์คํฌ๋กค ๋ทฐํฌํธ ์ธ๋ถ์ ์๋ ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ์ต๋๋ค.
์ ๊ฒฝ์ฐ์๋ ๋ชจ๋ ๋ชฉ๋ก์ ์ฒ์ 2๊ฐ ํญ๋ชฉ์ด ๊ธฐ๋ณธ ์ฝํ
์ธ ์ ์์ง ์คํฌ๋กค ๋ด์์ ํญ์ ํ์๋๋ค๋ ๊ฒ์ ์๊ณ ์์ผ๋ฏ๋ก ์คํฌ๋กค ์ปจํ
์ด๋๋ฅผ <ion-content #content>
ํฉ๋๋ค. ๊ทธ๋ฆฌ๊ณ ๋๋จธ์ง ๋ชฉ๋ก ํญ๋ชฉ์ ์ํ ์คํฌ๋กค์ <ion-scroll scrollX="true" #recentScroll>
๋ฉ๋๋ค.
<ion-content #content>
<!-- more ion-scrolls here -->
<ion-scroll #recentScroll scrollX="true">
<ng-container *ngFor="let subitem of recentItems; let i = index">
<horizontal-item [item]="subitem"
[scrollContainer]="content._scrollContent.nativeElement"
(openItem)="showItemDetails($event, true)"
*ngIf="i < 2"></horizontal-item>
<horizontal-item [item]="subitem"
[scrollContainer]="recentScroll._scrollContent.nativeElement"
(openItem)="showItemDetails($event, true)"
*ngIf="i >= 2"></horizontal-item>
</ng-container>
</ion-scroll>
<!-- more ion-scrolls here -->
</ion-content>
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
์๋ํฉ๋๋ค. ํต์ฌ์ scrollTarget์
scroll._scrollContent.nativeElement
์๋ ์ ์ฒด ์ฝ๋
``
javascript <ion-scroll scrollX="true" direction="x" #scroll1> <div class="item" margin *ngFor="let item of newItems" (click)="goToItemPage(item)"> <img src="./assets/imgs/placeholder.png" [lazyLoad]="item.photoThumb?.url()" [scrollTarget]="scroll1._scrollContent.nativeElement" /> <div text-center text-wrap> <p no-margin>{{ (item.shortName || item.name) | excerpt:17 }}</p> </div> </div> </ion-scroll>