以下滑动操作会在模板中加载三个图像。他们目前工作正常,但我想用功能性Google Maps iframe和复选框和名称循环更改两个图像。Angular - Hammerjs - 在滑动操作中加载html内容
我尝试用html替换图像链接,并将<img [src]="avatar.content" [alt]="">
更改为{{avatar.content}}
,但模板将纯HTML处理为纯文本。
完成此操作的最佳选择是什么?
component.ts
SWIPE_ACTION = { LEFT: 'swipeleft', RIGHT: 'swiperight' };
avatars = [
{
content: 'https://semantic-ui.com/images/avatar2/large/kristy.png',
visible: true
},
{
content: 'https://semantic-ui.com/images/avatar2/large/matthew.png',
visible: false
},
{
content: 'http://semantic-ui.com/images/avatar/large/jenny.jpg',
visible: false
}
];
// action triggered when user swipes
swipe(currentIndex: number, action = this.SWIPE_ACTION.RIGHT) {
// out of range
if (currentIndex > this.avatars.length || currentIndex < 0) { return };
let nextIndex = 0;
// swipe right, next avatar
if (action === this.SWIPE_ACTION.RIGHT) {
const isLast = currentIndex === this.avatars.length - 1;
nextIndex = isLast ? 0 : currentIndex + 1;
}
// swipe left, previous avatar
if (action === this.SWIPE_ACTION.LEFT) {
const isFirst = currentIndex === 0;
nextIndex = isFirst ? this.avatars.length - 1 : currentIndex - 1;
}
// toggle avatar visibility
this.avatars.forEach((x, i) => x.visible = (i === nextIndex));
}
component.html
<div class="swipe-box" *ngFor="let avatar of avatars; let idx=index" (swipeleft)="swipe(idx, $event.type)" (swiperight)="swipe(idx, $event.type)"
[class.visible]="avatar.visible" [class.hidden]="!avatar.visible">
<div class="swipe-content">
<img [src]="avatar.content" [alt]="">
</div>
</div>
这是复选框循环:
<md-list>
<md-list-item *ngFor="let guest of event['guests'] | keys">
<md-icon md-list-icon><img class="event-img" src="http://lorempixel.com/70/70" /></md-icon>
<h3 md-line> {{ guest.value.first_name }} {{guest.value.last_name}} </h3>
<p md-line>
</p>
<span flex>
<md-checkbox *ngIf="checkGuest(guest.key) === false" (change)="checkIn(guest.key)"></md-checkbox>
<md-checkbox *ngIf="checkGuest(guest.key) === true" (change)="checkOut(guest.key)" [checked]="true === true"></md-checkbox>
</span>
</md-list-item>
</md-list>
其中是checkIn,checkout功能 –