1

So I want to use a variable inside a iframe src or ng-src attribute. Apparently none of my variables get ever recognized, whatever I use. For example `

<iframe ng-src="http://www.example.com/?name={{test}}">
</iframe>

where test just get displayed as {{test}} ....

Also when I use $sce to use it as a trusted url it doesn't work, same goes for normal src..

Is there something I don't see? Is there something about Iframes and angularjs? Please share, its really annoying.

Thnx in advance.

2 Answers 2

1

You can try this, In your controller do - replace the ng-src="{{test}}" -- use a variable for the whole url. and then -

$scope.test=$sce.trustAsResourceUrl("https://www.example.com");

also include $sce in your controller dependency.

It worked for me.. Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

0

You can set the src property with this syntax:

iframeObject.src = URL

To note: URL specifies the URL of the content to embed and it can be either an absolute or a relative URL.

Example:

document.getElementById('embedContent').src = "http://www.example.com";
#embedContent{
        width: 600px;
        height: 500px;
    }
<iframe id="embedContent" src="#"></iframe>

Because you also want to concatenate / merge two strings, you can just change the JavaScript to

document.getElementById('embedContent').src = "http://www.example.com/?name=" + test;

Comments

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.