我在自己的Ionic 2项目中,使用卡片列出数据:
<ion-card *ngFor="let item of inspects">
卡片中有一个导航按钮,根据每项的数据生成连接打开百度地图,我是这样绑定的: 页面:
<a [href]="nav(item)" target="_blank" ion-button icon-left clear small>
<ion-icon name="pin"></ion-icon>
<div>导航</div>
</a>
代码:
nav(item) {
let url = `bdapp://map/navi?location=${item.lng},${item.lat}`;
if (Device.platform == 'iOS') {
url = `baidumap://map/direction?origin=34.264642646862,108.95108518068&destination=${item.lng},${item.lat}&mode=driving&coord_type=wgs84&src=webapp.navi.yourCompanyName.yourAppName`;
}
console.log(url);
return this.sanitizer.bypassSecurityTrustResourceUrl(url);
}
我查看console,发现一直在输出:
console一直在输出
原来这是Angular2在change detection cycle中不停的调用绑定的方法nav(item)。因此,建议不要在属性上绑定方法,因为调用太频繁了,最好预先计算好然后绑定一个值就好。
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有