如何在离子开关中放置文本 [英] How can I place text inside an ion-toggle
问题描述
目前我有一个看起来像这样的离子开关
Current I have a ion-toggle that looks like this
我想这样做
有没有办法做到这一点?我在某处读到我可以使用 ng-true-value 和 ng-false-value 但这似乎并没有做我正在寻找的
Is there anyway to make this happen? I read somewhere I could use ng-true-value and ng-false-value but that doesnt seem to do what I am looking for
推荐答案
ng-true-value
和 ng-false-value
属性用于提供ng-model
在复选框被选中时表达某个自定义值.ionic 框架不使用它在切换中显示文本.
The attributes ng-true-value
and ng-false-value
are to provide the ng-model
expression a certain custom value when the checkbox is checked. The ionic framework doesn't use it to display text in the toggle.
但这当然是可能的:)
下面是一个指令.将 ion-toggle-text
放在任何现有的 ion-toggle
上,你就可以开始了.可以使用 ng-true-value
/ng-false-value
属性或 ;
分隔值设置开/关文本ion-toggle-text
属性.如果未提供文本,则默认为on"&关闭".
Below is a directive that does. Slap ion-toggle-text
on any existing ion-toggle
and you're good to go. On/off text can be set with either the ng-true-value
/ng-false-value
attributes or with a ;
separated value with the ion-toggle-text
attribute. If no text is provided it defaults to "on" & "off".
<ion-toggle ion-toggle-text ng-model="simple">
Simple Example: <b>{{ simple || false }}</b>
</ion-toggle>
<ion-toggle ion-toggle-text="online;offline" ng-model="customText">
Custom text: <b>{{ customText || false }}</b>
</ion-toggle>
<ion-toggle ion-toggle-text ng-true-value="so true" ng-false-value="so false" ng-model="textByValue">
Text by value: <b>{{ textByValue || 'so false' }}</b>
</ion-toggle>
Plunker 可以在此处找到.
Plunker can be found here.
享受.
这篇关于如何在离子开关中放置文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!