I'm having a problem with a Iframe directive that I try to implement.
As far I am : Template:
<div class="externalIframe" iframe-src="external.html"></div>
Directive :
angular.module('project.directives', [])
.directive('externalIframe', ['$rootScope', function($rootScope) {
return {
restrict: 'C',
replace: true,
transclude: true,
scope: {
src: '@iframeSrc', // the src uses the data-binding from the parent scope
},
template: '<iframe src="{{src}}" height="100%" width="100%" frameborder="0"></iframe>',
link: function(scope, elem, attrs) {
//elem.src = "dummy.html"; // not working either
}
}
}])
Problem : It fires 2 HTTP request (2 iframe loading). :
- one to
http://localhost:8000/app/{{src}}(iframe src not yet interpreated by angular) - one to
http://localhost:8000/app/external.html(iframe src once interpreated by angular)
I want to avoid the useless first call.. How can I do that ?
I tried without src in the template and programmatically set it in the link or compile function but that doesn't fire the iframe loading.
edit: jsFiddle added for bug demo with compile method => you'll see in the network tab of firebug/chrome dev panel that two request are made :
http://fiddle.jshell.net/_display/%7B%7Bsrc%7D%7Dhttp://fiddle.jshell.net/_display/external.html
Thanks for the help