ionic2/ionic3 ion-item内部不渲染div或者span以及其他元素

在ionic2/3中,ion-item内部无法直接渲染div、span等自定义HTML元素,仅识别<ion-label>。遇到此类问题,可以采用两种解决办法:1. 使用<ion-note>组件;2. 添加item-start, item-end等属性到元素上,如<span item-content class="inline-edit">。问题源于ionic的特定布局规则,相关解答可参考StackOverflow链接。" 6442019,997471,使用PLSQL Developer进行Oracle数据库数据的导入导出,"['数据库', 'Oracle', 'PLSQL Developer', '数据迁移', 'Excel']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ionic2/ionic3  ion-item内部不渲染div或者span以及其他元素,可以说是任何自定义的html元素

只识别<ion-label>

但是如下结构

<ion-input type="number"  placeholder="请输入最小值"></ion-input>
    <ion-label>至</ion-label>
    <ion-input type="number" placeholder="请输入最大值"></ion-input>
</ion-item>

你猜怎么着,中间的label元素渲染后居然跑到第一个去了,崩溃。。。。

其他的结构

<ion-input type="number"  placeholder="请输入最小值"></ion-input>
    <span>至</span>
    <div>至</div>
    <ion-input type="number" placeholder="请输入最大值"></ion-input>
</ion-item>

中间俩元素直接不渲染,查看渲染后的网页,这俩直接就没有,蹦。。。。

最后参考了,大神们的博客,根本原因如下:https://stackoverflow.com/questions/44448237/ionic-2-cannot-view-span-inside-of-ion-item-how-to-render-simple-text

That's because of how content projection works, the ion-item will only render some components (like the ion-label and the ion-input) but will ignore some other html elements.

解决方法有2种:

1. 用ionic组件<ion-note>

2. 给元素加上item-start, item-end, item-left, item-right or item-content 这些属性, 我就用的这个方法:<span item-content class="inline-edit">至</span>问题解决。

以下是stackoverflow大神的解答:

https://stackoverflow.com/questions/44448237/ionic-2-cannot-view-span-inside-of-ion-item-how-to-render-simple-text

 

其他说明:

Attribute       Description
item-start      Placed to the left of all other elements, outside of the inner item.
item-end        Placed to the right of all other elements, inside of the inner item, outside of the input wrapper.
item-content    Placed to the right of any ion-label, inside of the input wrapper.

另外,ionic4官网也有

<ion-note>Default Note</ion-note>

说明,之前的V3没有这个说明,https://ionicframework.com/docs/api/note

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值