0

I have an iframe control in View.

<iframe width="100%" height="800" ng-src="{{IframeSrcUrl}}"></iframe>

In the controller, I have a scope variable like below. But the iframe is not getting the url from scope variable. Also, how do we append additional query string parameters in the controller?

$scope.IframeSrcUrl = 'https://mmr.com';

Thanks!

2
  • SCE maybe the reason for this check, stackoverflow.com/questions/19289402/… Commented Mar 30, 2015 at 3:45
  • ng-src="IframeSrcUrl" should be your markup. Since ng-src is an angular specific attribute, it won't require {{}} interpolation Commented Mar 30, 2015 at 4:25

1 Answer 1

5

Use $sce service for this for example:-

<iframe width="100%" height="800" ng-src="{{IframeSrcUrl | trustAsResourceUrl}}"></iframe>


app.filter('trustAsResourceUrl', ['$sce', function($sce) {
    return function(val) {
        return $sce.trustAsResourceUrl(val);
    };
}])
Sign up to request clarification or add additional context in comments.

1 Comment

@squiroid hey I had the same problem and your answer solved it. But there's one problem though. I have a list of items and on clicking each item, the frame should be opened and the src changes dynamically. But, on clicking the item iframe reloads on its own, which disturbs the iframes opened. What shall I do now?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.