Javascript 无法通过angularjs在phonegap中显示联系人照片
我能够从简单的html和javascript获取和显示联系人照片,但是当我使用angularjs模型显示联系人照片时,我得到了一个错误。以下是我的源代码: 列出我试图显示联系人的位置:Javascript 无法通过angularjs在phonegap中显示联系人照片,javascript,android,angularjs,cordova,contact-list,Javascript,Android,Angularjs,Cordova,Contact List,我能够从简单的html和javascript获取和显示联系人照片,但是当我使用angularjs模型显示联系人照片时,我得到了一个错误。以下是我的源代码: 列出我试图显示联系人的位置: <ul class="list"> <li class="item item-thumbnail-left" ng-repeat="contact in contactList"> <img ng-src="{{contact.mphoto}}"/&g
<ul class="list">
<li class="item item-thumbnail-left" ng-repeat="contact in contactList">
<img ng-src="{{contact.mphoto}}"/> <!--When I put this path directly ( ie "content://com.android.contacts/contacts/30/photo"), I am able to display the image, but when I fetch it from the controller, I am getting error: "unable to read contacts from asset folder" -->
<h2>{{contact.name}}</h2>
<p >{{contact.number}}</p>
</li>
</ul>
-
{{contact.name}
{{contact.number}
这是我的控制器,用于设置联系人列表:
ContactService.find("").then(function(contacts) {
for (var i = 0; i < contacts.length; i++)
{
if (contacts[i].phoneNumbers !== null)
{
for (var j = 0; j < contacts[i].phoneNumbers.length; j++)
{
var img = contacts[i].photos != null ? contacts[i].photos[0].value : "img/default.png";
$scope.contactList.push({name: contacts[i].name.formatted, number: contacts[i].phoneNumbers[j].value, mphoto: img})
}
}
}
ContactService.find(“”)。然后(函数(contacts){
对于(变量i=0;i
经过这么多的努力,我终于找到了问题所在
请在App.js文件中粘贴以下行,问题将得到解决,不显示照片的原因是Angularjs在每个url之前添加了不安全:如果不受信任
config(['$compileProvider', function($compileProvider) {
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|blob|content):|data:image\//);
}]);
经过这么多的努力我终于能够找到问题了 请在App.js文件中粘贴以下行,问题将得到解决,不显示照片的原因是Angularjs在每个url之前添加了不安全:如果不受信任
config(['$compileProvider', function($compileProvider) {
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|blob|content):|data:image\//);
}]);
我在Angular 2中遇到了这个问题,但我不知道这是个问题,我也不知道如何尝试Angular 2中的接受者答案。为了完整性,下面是如何使用Ionic 2解决这个问题: 在控制器/服务中注入
消毒剂:domsanizer
然后调用:sanitizer.bypassSecurityTrustUrl(photoURL)
下面是一个例子:
export class HomePage {
url;
constructor(public navCtrl: NavController, platform: Platform, sanitizer: DomSanitizer) {
platform.ready().then(() => {
Contacts
.pickContact()
.then((contact) => {
alert(JSON.stringify(contact));
if (contact.photos) {
var photoURL = contact.photos[0].value;
this.url = sanitizer.bypassSecurityTrustUrl(photoURL);
}
});
})
}
}
我在Angular 2中遇到了这个问题,但我不知道这是个问题,我也不知道如何尝试Angular 2中的接受者答案。为了完整性,下面是如何使用Ionic 2解决这个问题: 在控制器/服务中注入
消毒剂:domsanizer
然后调用:sanitizer.bypassSecurityTrustUrl(photoURL)
下面是一个例子:
export class HomePage {
url;
constructor(public navCtrl: NavController, platform: Platform, sanitizer: DomSanitizer) {
platform.ready().then(() => {
Contacts
.pickContact()
.then((contact) => {
alert(JSON.stringify(contact));
if (contact.photos) {
var photoURL = contact.photos[0].value;
this.url = sanitizer.bypassSecurityTrustUrl(photoURL);
}
});
})
}
}
你找到问题的根源了吗?我也有同样的问题?还没有运气,同样的东西在IOS上工作,但在IOS上没有android@user1255162请参考下面的答案,它会解决你的问题吗?你找到问题的根源了吗?我也有同样的问题?还没有运气,同样的东西在IOS中工作,但在IOS中没有android@user1255162ple请参考下面的答案,它可能会解决您的问题。太棒了,解决这个问题做得很好,非常感谢您的分享。哇,感谢您解决了这个问题。Vivek,在过去的一个小时里,我一直在努力解决这个问题。@reitoei谢谢:)我也花了3个月的时间来弄明白这一点:DThanks。我希望我能投两次票。我最初选择的是$sce.trustAs路线,它适用于iOS,但不适用于Android。这更干净。太棒了,这一点做得很好,非常感谢分享。哇,谢谢你弄明白了这一点,Vivek,一直在敲我的头“过去一个小时我一直在努力解决这个问题。@reitoei谢谢:)我也用了三个月的时间来解决这个问题:DThanks。我希望我能投票两次。我最初选择的是$sce.trustAs路线,它适用于iOS,但不适用于Android。这更干净。