radioaktiv
radioaktiv

Reputation: 2539

iframe not working properly with ionic/angular js

I am using iframe in my ionic app to open webpages inside the application.

Here is what I have:

  <iframe  class= 'webPage' name= "eventsPage" ng-src="{{object.url}}"></iframe>

The problem is that if I use ng-src="{{object.url}} or src="{{object.url}}for getting the URL the iframe doesnt not display anything but if I put hardcoded url instead (example http://www.google.com) it just works fine.

I have also check the output of the {{object.url}} and it's fine, a valid url (http://www.example.com).

Any suggestions ?

Upvotes: 0

Views: 1132

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222582

You need to inject the $sce service in the controller and trustAsResourceUrl the url there.

 <iframe   ng-src="{{trustSrc(object.url)}}"></iframe>

and in controller

 $scope.trustSrc = function(src) {
       return $sce.trustAsResourceUrl(src);
  }

Upvotes: 3

Related Questions