可以将图标添加到ion-select中的ion-option吗?就像这样
<ion-select name="type">
<ion-option value="bar"><ion-icon name="stats"></ion-icon>Bar</ion-option>
<ion-option value="pie"><ion-icon name="pie"></ion-icon>Pie</ion-option>
</ion-select>发布于 2019-04-22 02:56:22
你可以试试这个..。
这对我很有效..查看此站点:https://www.alt-codes.net/star_alt_code.php
我使用的代码是:✰
所以我的代码看起来像这样:
<ion-item>
<ion-label>Member's Overall Rating</ion-label>
<ion-select [(ngModel)]="newreport.memberstatus">
<ion-option value="✰">✰</ion-option>
<ion-option value="✰✰">✰✰</ion-option>
<ion-option value="✰✰✰">✰✰✰</ion-option>
<ion-option value="✰✰✰✰">✰✰✰✰</ion-option>
<ion-option value="✰✰✰✰✰">✰✰✰✰✰</ion-option>
</ion-select>
</ion-item>结果是这样的(我手机上的屏幕截图导致我手机上的im测试):
发布于 2018-03-14 06:01:22

这对我很有效。
使用CSS修改每个选项的按钮标记中的内部跨度,删除半径并指定一个背景图像
选项保持相同的顺序,这就是属性选择器适用于我的原因
.alert-radio-icon{
border-radius: 0 !important;
border: none !important;
height: 40px !important;
width: 40px !important;
background-size: 40px 40px !important;
background-repeat: no-repeat ;
}
[id^="alert-input-"][id$="-0"] .alert-radio-icon{
background-image: url("../assets/images/menu/flag_ni.png") !important;
}
[id^="alert-input-"][id$="-1"] .alert-radio-icon{
background-image: url("../assets/images/menu/flag_gt.png") !important;
}
.alert-radio-inner{
background-color: transparent !important;
}发布于 2020-07-29 22:02:04
IonSelect中的IonIcons:

ion-select-option只返回字符串,然而,从技术上讲,Ion-Select所做的一切只是显示一个看起来像下拉菜单的界面。
简而言之,在本例中,您可以做的是创建一个popover组件,通过将dropdown放在可点击的ion-item中,禁用dropdown,使其看起来已启用(对于UX),当ion-item被单击时单击下拉,然后使用该引用在该位置打开popover组件。
所以,我在这样做的时候做了一些考虑:
我最终得到的解决方案(请注意,这也是使用ReactiveForms):
menu-options.interface.ts
export interface MenuOptions {
key: string;
fn: () => {};
}MenuOptions将保存要显示的值和按下按钮时要运行的函数
main.component.ts
constructor(private cd: ChangeDetectorRef){}
menuOptions: MenuOptions[] = [
{
key: "Text",
fn: () =>
this._showAlert("Select this option if you want to type in values"),
},
{
key: "List",
fn: () =>
this._showAlert(
"Select this option if you want to use a pre-defined list of values"
),
},
{
key: "Textbox",
fn: () =>
this._showAlert(
"Select this option if you want an area to type a block of text"
),
},
];
// Find location of where popover is to appear and click the element
// which will then trigger the (click) event
onSelectionClick(event: any) {
let element: HTMLElement = document.getElementById('popoverLoc') as HTMLElement;
element.click();
}
async openPopover(event: any) {
const popover = await this.popover.create({
component: SelectionTypePopoverComponent,
componentProps: {
menuOptions: this.menuOptions
},
event,
translucent: true,
});
await popover.present();
const {data} = await popover.onWillDismiss();
// Get return from popover and set selection value
this.itemFeatureForm.get('selectionType').setValue(data['selectionType']);
// If you hardcode the menu options directly in the popover component and pass them back
// you will need to trigger change detection manually and set array to have 1 value
// otherwise your dropdown wont appear properly
// menuOptions: MenuOptions[] = [{ key: '', fn: () => '' }]
//this.cd.detectChanges();
}main.component.html
<ion-item button (click)="onSelectionClick($event)" detail="false">
<ion-label class="enableItem">Selection Type</ion-label>
<ion-select
formControlName="selectionType"
class="enableItem"
id="popoverLoc"
(click)="openPopover($event)"
>
<ion-select-option
*ngFor="let option of menuOptions"
[value]="option.key"
>{{ option.key }}</ion-select-option
>
</ion-select>
</ion-item>确保您的离子选择被禁用:selectionType: new FormControl({value: '', disabled: true}),
使您的离子选择看起来已启用的
.enableItem {opacity: 1 !important;}的位置
popover.component.html
<ion-list>
<div *ngFor="let option of menuOptions; let i = index">
<ion-grid class="ion-no-padding">
<ion-row class="ion-no-padding">
<ion-col class="ion-no-padding">
<ion-item button detail="false" (click)="onSelection(i)">
<ion-label>{{ option.key }}</ion-label>
</ion-item>
</ion-col>
<ion-col class="ion-no-padding" size="2">
<ion-item class="ion-no-padding">
<ion-button class="ion-no-padding" fill="clear" (click)="onInfo(i)">
<ion-icon
name="information-circle-outline"
slot="icon-only"
></ion-icon>
</ion-button>
</ion-item>
</ion-col>
</ion-row>
</ion-grid>
</div>
</ion-list>确保设置图标列的大小
popover.component.ts
onSelection(index: number) {
this.popoverCtrl.dismiss({
selectionType: this.menuOptions[index].key,
});
}
onInfo(index: number) {
this.menuOptions[index].fn();
}我还没有在物理设备上做测试,但当我做了测试时,如果这不起作用,我会更新,但目前,通过这个模式,我可以在下拉列表中显示我想要显示的任何东西,并且仍然使用ionic templating...great的能力、责任和所有这些。
https://stackoverflow.com/questions/44119567
复制相似问题