2
私は1から3までループしているタイマーを持っていて、各ループでその番号で画像をロードしたいURLにdynnamicのイメージを持つAngular2タイマーurl - 式が期待される補間({{}})があります
成分画像がsignup-step1.gif
、signup-step2.gif
とsignup-step3.gif
ある資産に
import { Component, OnInit, OnDestroy} from "@angular/core";
import { Observable } from 'rxjs/Observable';
import { Subscription } from "rxjs";
@Component({
selector: 'animated-content',
template: require('./animated-content.template.html')
})
export class AnimatedContentComponent implements OnInit{
highlightedItem = 1;
private sub: Subscription;
constructor(){
}
ngOnInit(){
let timer = Observable.timer(1,2000);
this.sub = timer.subscribe(t => this.startContentCycle(t))
}
private startContentCycle(highlightedItem) {
if (this.highlightedItem === 3) {
this.highlightedItem = 1;
} else {
this.highlightedItem++;
}
}
}
テンプレート
<img [src]="/assets/signup-step{{highlightedItem}}.gif" alt="" class="img-responsive">
。
が、私はこのエラーを取得しています:
'Got interpolation ({{}}) where expression was expected'
はい、@OP:これらのような場合には、関数内のそのようなものをうまく抽出します。これにより、TS/ES6文字列補間を使用してhtmlをより明確にすることができます –