Unable to display contact photo in phonegap through angularjs

后端 未结 2 840
谎友^
谎友^ 2021-01-07 11:09

I am able to fetch and display the contact photo from simple html and javascript but when I use angularjs model to display the contact photo, I get an error. Following is my

2条回答
  •  一生所求
    2021-01-07 11:51

    I was having this issue in Angular 2 with Ionic 2 but I didn't know this was the problem and I didn't know how to try the accepter answer in angular 2. For the sake of completeness, here is how you would fix it using Ionic 2:

    Inject sanitizer: DomSanitizer in your controller/service.

    then call: sanitizer.bypassSecurityTrustUrl(photoURL)

    Here's an example:

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

提交回复
热议问题