大佬教程收集整理的这篇文章主要介绍了angularjs – 如何避免通过Angular-2链接添加前缀“unsafe”?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<a ion-button href="tel:{{Contact.cellphonE}}" color="priMary"> <ion-icon name="call"></ion-icon> Call </a> <a ion-button href="sms:{{Contact.cellphonE}}" color="secondary"> <ion-icon name="text"></ion-icon> SMS </a> <a ion-button href="mailto:{{Contact.email}}" color="dark"> <ion-icon name="mail"></ion-icon> Email </a>
电话和电子邮件工作正常,但不是短信,似乎角度添加不安全:在我的表达前面,它将变为如下
<a color="secondary" ion-button="" ng-reflect-color="secondary" class="button button-md button-default button-default-md button-md-secondary" ng-reflect-href="unsafe:sms:+16475374201" href="unsafe:sms:+16475374201"><span class="button-inner">
即使我试过这个
<a ion-button [attr.href]="'sms:'+contact.cellphone" color="secondary"> <ion-icon name="text"></ion-icon> SMS </a>
还是一样的问题,
当我不使用角度绑定时,它工作正常,例如像这样
<a ion-button href="sms:+1647654654" color="secondary"> <ion-icon name="text"></ion-icon> SMS </a>
虽然它与angular有关,但我也检查了我的config.xml,并允许短信存在
<allow-intent href="tel:*" /> <allow-intent href="sms:*" /> <allow-intent href="mailto:*" /> <allow-intent href="geo:*" />
更新
使用@Apuu解决方案后,它变得如下
<a ion-button [attr.href]="'sms:'+contact.cellphone | safeUrl" color="secondary"> <ion-icon name="text"></ion-icon> SMS </a>
创建名为safe-url.pipe.ts的管道服务.
import { Pipe,PipeTransform } from '@angular/core'; import { DomSanitizer } from '@angular/platform-browser'; @Pipe({ name: 'safeUrl' }) export class SafeUrlPipe implements PipeTransform { constructor(private domSanitizer: DomSanitizer) {} transform(url) { return this.domSanitizer.bypassSecurityTrustresourceUrl(url); } }
然后在您的视图中使用.
示例:
<a ion-button [src]="'some_url' | safeUrl" color="secondary"> <ion-icon name="text"></ion-icon> SMS </a>
注意:不要忘记在app.module.ts中注入此管道服务
import { SafeUrlPipe } from './shared/safe-url.pipe'; //make sure your safe-url.pipe.ts file path is matching.
并在您的节点模块声明部分中.
@NgModule({ declarations: [SafeUrlPipe],...});
以上是大佬教程为你收集整理的angularjs – 如何避免通过Angular-2链接添加前缀“unsafe”?全部内容,希望文章能够帮你解决angularjs – 如何避免通过Angular-2链接添加前缀“unsafe”?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。