我使用的是基于离子栅的自举网格系统。下面是我为不同元素使用的代码的简化版本:
<ion-grid>
<ion-row *ngFor="let task of allTasks">
<ion-col *ngIf="task.author === this.currentUser" offset-3 col-9 class="task">
<div>{{task.description}}</div>
</ion-col>
</ion-row>
</ion-grid>我的离子栅格有12列.offset-3基本上会将元素推到列的最右边。然而,我希望有条件地改变这个属性,有两种方式:
offset-3应用于此元素。正确的语法是什么:myCondition ? "offset-3" : ""offset-{value}?如果将col-auto赋值给上面的元素,如何更改offset-{value}的{value},使其不小于3或更大?例如,col-auto将col-6分配给元素,将offset-{value}更改为offset-6,或者简单地将元素推送到列的最右边。我不确定2.实际上是否有可能实现,但是任何解决方法,如果有相同的结果,对我来说就足够了。
发布于 2018-07-15 22:03:24
在组件中创建一个@input属性,然后将值传递给html;偏移{inputValue},也许可以在组件中执行更多的逻辑。并将值传递给HTML,以便在html中设置该值之前检索该值。
榜样;
your components.ts;
@Input() value: string;
You create a new method lets say;
getOffsetValue() {
if (x === foo) {
this.value = '1';
}else {
this.value = '2';
}
return this.value
}
ngOnInit()
// call method
getOffsetValue();
So now you have a data on the value attribute
in your HTML;
offSet{{this.value}}https://stackoverflow.com/questions/51352541
复制相似问题