一度に最初のdivだけを表示し、他のdivをすべて非表示にしたかったのです。ボタンのクリックで2番目のdivを表示し、他のすべてのdivを非表示にする必要があります。一度に最初のdivだけを表示し、ほかのdivをすべて非表示にしたい
コンポーネントテンプレート:
@Component({
selector: 'question',
template: `<div class="slide-{{question.id}}" [ngClass]="{hide: isOn}" *ngFor="let question of questions">
<div class="section-head text-center">{{question.heading}}</div>
<div class="section-desc text-center">{question.description}}</div>
</div>
<div class="action">
<div class="col-md-12 text-center">
<button type="button" class="btn prime prev-step ripple hide"><i class="material-icons pull-left">arrow_back</i> Prev </button>
<button (click)="toggle(!isOn)" type="button" class="btn prime next-step ripple">Next <i class="material-icons pull-right">arrow_forward</i></button>
</div>
</div>`
})
クラス:
export class Question{
id: number;
heading: string;
description: string;
field: string;
isOn = false;
toggle(newState) {
this.isOn = newState;
}
}
ギュンターZöchbauer:こちらをクリックコンパイラの解析することができません。だから私はこのような値を増分しています(クリック)= "増分(showIdx)"と関数増分(showIdx){ showIdx ++; } .............ボタンをクリックすると、それ以上のdivは表示されません – Bhawna
この関数は 'increment(){this.showIdx ++; }または '(クリック)=" showIdx = showIdx + 1 "または'(クリック)= "showIdx + = 1" '私はテンプレートがサポートしている演算子が何であるか分かりません(残念ですが、 '++'は期待していました)。 –