角离子图标结合不编译

发布于 2025-02-13 15:22:33 字数 802 浏览 0 评论 0原文

我有一个自定义版本的< ion-select>我使用标准< ion-select-option>

<custom-select>
    <ion-select-option></ion-select-option>
</custom-select>

当我像这样绑定图标时,

<ion-select-option value="test" icon="information-circle">
    Test
</ion-select-option>

代码编译,自定义包装器组件会在适当的位置添加图标。

但是,当我这样绑定时,

<ion-select-option value="test" [icon]="getIcon()">Test2</ion-select-option>

我会得到错误无法绑定到“图标”,因为它不是“离子 - 选择选项”的已知属性。

我需要后者,因为添加图标是有条件的。

示例: stackblitz链接

I have a custom version of <ion-select> under which I use the standard <ion-select-option>.

<custom-select>
    <ion-select-option></ion-select-option>
</custom-select>

When I bind an icon like this

<ion-select-option value="test" icon="information-circle">
    Test
</ion-select-option>

The code compiles and the custom wrapper component takes care of adding the icon in the appropriate place.

But when I bind it like this

<ion-select-option value="test" [icon]="getIcon()">Test2</ion-select-option>

I get error Can't bind to 'icon' since it isn't a known property of 'ion-select-option'.

I need the latter because adding the icon is conditional.

Example: stackblitz link

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

渡你暖光 2025-02-20 15:22:33

ion-select-option没有iCON属性,检查 docs

您可以创建自己的选择组件并加载到 popover

例如

component.html

...
<ion-list>
    <ion-item (click)="selectItem('test')">
        <ion-icon slot="end" name="logo-ionic"></ion-icon>
        <ion-label>Test</ion-label>
    </ion-item>
</ion-list>
...

component.ts

...
constructor(public popoverController: PopoverController) {}

selectItem(val) {
    this.popoverController.dismiss(val);
}
...

home.ts home.ts

async presentPopover(e: Event) {
    const popover = await this.popoverController.create({
      component: PopoverComponent,
      event: e
    });

    await popover.present();

    const { role } = await popover.onDidDismiss();
    this.roleMsg = `Popover dismissed with role: ${role}`;
}

ion-select-option don't have icon property, check the docs

You can create your own select component and load into a popover

For example

component.html

...
<ion-list>
    <ion-item (click)="selectItem('test')">
        <ion-icon slot="end" name="logo-ionic"></ion-icon>
        <ion-label>Test</ion-label>
    </ion-item>
</ion-list>
...

component.ts

...
constructor(public popoverController: PopoverController) {}

selectItem(val) {
    this.popoverController.dismiss(val);
}
...

home.ts

async presentPopover(e: Event) {
    const popover = await this.popoverController.create({
      component: PopoverComponent,
      event: e
    });

    await popover.present();

    const { role } = await popover.onDidDismiss();
    this.roleMsg = `Popover dismissed with role: ${role}`;
}
她比我温柔 2025-02-20 15:22:33

我找到了一个解决方案,使用attr.icon工作:

<ion-select-option
  value="test2"
  attr.icon="{{ 1===1 ? 'information-circle' : null }}"
>
  Test2
</ion-select-option>

我仍然不知道为什么它有效,尽管离子选择选项没有正式具有ICON属性。

I found a solution, using attr.icon works:

<ion-select-option
  value="test2"
  attr.icon="{{ 1===1 ? 'information-circle' : null }}"
>
  Test2
</ion-select-option>

I still don't know why it works although ion-select-option does not have icon attribute officially.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文