Viv*_*ngh 1 javascript android contact-list angularjs cordova
我能够从简单的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>
Run Code Online (Sandbox Code Playgroud)
这是我设置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})
}
}
}
Run Code Online (Sandbox Code Playgroud)
Viv*_*ngh 10
经过这么多的努力,我终于找到了问题,
请将以下行粘贴到App.js文件中,问题将得到解决,不显示照片的原因是Angularjs添加不安全:如果不受信任,则在每个url之前.
config(['$compileProvider', function($compileProvider) {
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|ftp|file|blob|content):|data:image\//);
}]);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2198 次 |
| 最近记录: |