无法通过angularjs在phonegap中显示联系人照片

2023-12-13

我能够从简单的 html 和 javascript 获取并显示联系人照片,但是当我使用 angularjs 模型显示联系人照片时,出现错误。以下是我的源代码:

列出我尝试显示联系人的位置:

<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>

这是我用于设置 ContactList 的控制器:

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})
                }
            }
        }

经过如此多的努力,我终于能够找到问题所在,

请将以下行粘贴到您的 App.js 文件中,问题将得到解决,不显示照片的原因是 Angularjs 在每个 url 之前添加 unsafe: 如果不可信。

 config(['$compileProvider', function($compileProvider) {
            $compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|blob|content):|data:image\//);
        }]);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法通过angularjs在phonegap中显示联系人照片 的相关文章

随机推荐