【发布时间】:2017-03-09 18:01:25
【问题描述】:
我有这样的组件
@Component({
templateUrl:"home.html",
})
export class HomePage {
current:any
heroes=[{name:"hero1",detail:"h1detail"}, {name:"hero2",detail:"h2detail"}]
constructor() {
}
tdetail(h){
if (current!=h.name){
current = h.name
}
else{
current = ""
}
}
}
和html模板home.html
<ion-navbar positive *navbar>
<ion-title>
Hero
</ion-title>
</ion-navbar>
<ion-content class="xm-new-order">
<ul class="event">
<li *ngFor="let hero of heroes">
<button (click)="tdetail(hero)">
{{hero.name}}
</button>
<p *ngIf="current==hero.name" >
{{hero.detail}}
</p>
</li>
</ul>
</ion-content>
代码将显示英雄名称按钮列表。当我单击任何按钮时,我想切换显示/隐藏英雄详细信息,但它没有发生。我该如何解决这个问题?
编辑:错字
【问题讨论】:
标签: angular ionic2 angular-ng-if