在类中切换2个值 [英] Switch between 2 values in a class
本文介绍了在类中切换2个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在一个类中切换2个值。
I want to switch between 2 values in a class.
像这样的东西,
<ion-item *ngFor="let part of partner" class="border_bottom bdr_radius">
<p class="font_c_2 gra_reg" #short (click)="onShowHide(short)" [ngStyle]="{'white-space': whiteSpace}">
{{part.fsp_partner_location}}
</p>
</ion-item>
public onShowHide(controlToShow) {
this.render.setStyle(controlToShow, white-space=='normal' ? 'nowrap' : 'normal');
}
上面的代码抛出错误:未定义白色
Above code is throwing an error: "white is not defined"
我知道我的格式不正确,我们将不胜感激任何帮助。
I know my format is not correct, any help will be appreciated.
谢谢
推荐答案
现在当我知道你的代码时,我将会这样做:
Now when I know your code this is what I will do :
HTML part:
HTML part:
<ion-item *ngFor="let part of partner; let i=index" class="border_bottom bdr_radius">
<p class="font_c_2 gra_reg" #short (click)="onShowHide(i)" [ngClass]="{'long': selected === i, 'short': selected != i}">
{{part.fsp_partner_location}}
</p>
</ion-item>
css part:
.long {
white-space: normal;
}
.short{
white-space: nowrap;
}
你的ts档案:
selected = 0;
onShowHide(index: number) {
this.selected = index;
}
点击项目时,它会设置正常
对于它和其他人有
nowrap
When you click on item it will set normal
for it and others will have
nowrap
这篇关于在类中切换2个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文