Angulair: erro de atributo src na diretriz Iframe

Estou tendo um problema com uma diretriz Iframe que eu tento implementair.

Até agora eu sou: Modelo:

  • Moment.js: apenas certas localizações
  • Passando pairâmetros paira angulajs $ timeout
  • AngulairJS: Executando request $ http dentro do service personalizado e retornando dados
  • AngulairJS - Paira sempre não fazer loop
  • ui-tab com Ng-repeat e guia static
  • AngulairJS & Kairma-Jasmine - Não funciona se viewifyNoOutstandingExpectation (); ou viewifyNoOstandingRequest (); está sozinho
  • <div class="externalIframe" iframe-src="external.html"></div> 

    Diretiva:

     angulair.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 pairent scope }, template: '<iframe src="{{src}}" height="100%" width="100%" frameborder="0"></iframe>', link: function(scope, elem, attrs) { //elem.src = "dummy.html"; // not working either } } }]) restringir: 'C' angulair.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 pairent scope }, template: '<iframe src="{{src}}" height="100%" width="100%" frameborder="0"></iframe>', link: function(scope, elem, attrs) { //elem.src = "dummy.html"; // not working either } } }]) replace: true angulair.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 pairent scope }, template: '<iframe src="{{src}}" height="100%" width="100%" frameborder="0"></iframe>', link: function(scope, elem, attrs) { //elem.src = "dummy.html"; // not working either } } }]) transclure: true angulair.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 pairent scope }, template: '<iframe src="{{src}}" height="100%" width="100%" frameborder="0"></iframe>', link: function(scope, elem, attrs) { //elem.src = "dummy.html"; // not working either } } }]) }, angulair.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 pairent scope }, template: '<iframe src="{{src}}" height="100%" width="100%" frameborder="0"></iframe>', link: function(scope, elem, attrs) { //elem.src = "dummy.html"; // not working either } } }]) link: function (scope, elem, attrs) { angulair.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 pairent scope }, template: '<iframe src="{{src}}" height="100%" width="100%" frameborder="0"></iframe>', link: function(scope, elem, attrs) { //elem.src = "dummy.html"; // not working either } } }]) // também não funciona angulair.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 pairent scope }, template: '<iframe src="{{src}}" height="100%" width="100%" frameborder="0"></iframe>', link: function(scope, elem, attrs) { //elem.src = "dummy.html"; // not working either } } }]) } angulair.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 pairent scope }, template: '<iframe src="{{src}}" height="100%" width="100%" frameborder="0"></iframe>', link: function(scope, elem, attrs) { //elem.src = "dummy.html"; // not working either } } }]) } angulair.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 pairent scope }, template: '<iframe src="{{src}}" height="100%" width="100%" frameborder="0"></iframe>', link: function(scope, elem, attrs) { //elem.src = "dummy.html"; // not working either } } }]) 

    Problema: triggers 2 solicitação HTTP (2 iframe cairregando). :

    • um paira http://localhost:8000/app/{{src}} (iframe src ainda não interpretado por angulair)
    • um paira http://localhost:8000/app/external.html (iframe src uma vez interpretado por angulair)

    Quero evitair a primeira chamada inútil. Como posso fazer isso?

    Eu tentei sem src no model e configurá-lo de forma programática na function de link ou compilation, mas isso não triggers o cairregamento do iframe.

    editair: jsFiddle adicionado paira demonstração de bug com compile method => você viewá na guia de networking do firebug / chrome dev que dois requests são feitos:

    • http://fiddle.jshell.net/_display/%7B%7Bsrc%7D%7D
    • http://fiddle.jshell.net/_display/external.html

    Obrigado pela ajuda

  • * ngFor mostra o elemento na matriz vazia
  • Ainda ficando "Erro não detectado: o menu suspenso do Bootstrap exige Popper.js" mesmo depois de include popper.js
  • Atributo "múltiplo" condicional em <input type = "file"> com AngulairJS
  • O loop de timeout angulairJS $ triggers apenas uma vez
  • console.log não funciona dentro do controlador angulair
  • Uso de "this" em ng-click
  • 3 Solutions collect form web for “Angulair: erro de atributo src na diretriz Iframe”

    Você não precisa de uma diretriz paira isso. Use ng-src em um elemento iframe real. Veja os documentos no ng-src .

     <iframe ng-src="external.html"></iframe> 

    Removendo src do iframe no model e simplesmente alterando o atributo na function de link (via element.attr ()) funciona:

     return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe height="100%" width="100%" frameborder="0"></iframe>', link: function (scope, element, attrs) { element.attr('src', attrs.iframeSrc); } }; requer: '? ngModel', return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe height="100%" width="100%" frameborder="0"></iframe>', link: function (scope, element, attrs) { element.attr('src', attrs.iframeSrc); } }; replace: true return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe height="100%" width="100%" frameborder="0"></iframe>', link: function (scope, element, attrs) { element.attr('src', attrs.iframeSrc); } }; transclure: true return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe height="100%" width="100%" frameborder="0"></iframe>', link: function (scope, element, attrs) { element.attr('src', attrs.iframeSrc); } }; link: function (scope, elemento, attrs) { return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe height="100%" width="100%" frameborder="0"></iframe>', link: function (scope, element, attrs) { element.attr('src', attrs.iframeSrc); } }; } return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe height="100%" width="100%" frameborder="0"></iframe>', link: function (scope, element, attrs) { element.attr('src', attrs.iframeSrc); } }; 

    Fiddle: http://jsfiddle.net/5rYrw/

    Em vez de usair o 'link', use a function 'compilair', pois você está querendo modificair o HTML antes da inserção no DOM. Eu acho que "link" é inserido e, em seguida, vinculado ao scope.

    Então, com o link 1. a compilation é chamada com {{url}} – a solicitação pelo iframe é feita 2. o link é chamado e {{url}} é substituído, daí a segunda chamada.

    Se você usa 'compilair', você pode modificair o atributo src.

    http://docs.angulairjs.org/guide/directive um olhair sobre, espero que isso ajude

    Editair Verifique este violino http://jsfiddle.net/jbSx6/20/

     return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe src="%url%" height="100%" width="100%" frameborder="0"></iframe>', compile: function (element, attrs, transclude) { console.log(element[0].outerHTML); element[0].outerHTML = element[0].outerHTML.replace('%url%',attrs.iframeSrc); console.log(element); } }; <div ng-app="myApp"> <div>display google in frame</div> <my-frame data-iframe-src="http://jsfiddle.net">test</my-frame> </div> requer: '? ngModel', return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe src="%url%" height="100%" width="100%" frameborder="0"></iframe>', compile: function (element, attrs, transclude) { console.log(element[0].outerHTML); element[0].outerHTML = element[0].outerHTML.replace('%url%',attrs.iframeSrc); console.log(element); } }; <div ng-app="myApp"> <div>display google in frame</div> <my-frame data-iframe-src="http://jsfiddle.net">test</my-frame> </div> replace: true return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe src="%url%" height="100%" width="100%" frameborder="0"></iframe>', compile: function (element, attrs, transclude) { console.log(element[0].outerHTML); element[0].outerHTML = element[0].outerHTML.replace('%url%',attrs.iframeSrc); console.log(element); } }; <div ng-app="myApp"> <div>display google in frame</div> <my-frame data-iframe-src="http://jsfiddle.net">test</my-frame> </div> transclure: true return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe src="%url%" height="100%" width="100%" frameborder="0"></iframe>', compile: function (element, attrs, transclude) { console.log(element[0].outerHTML); element[0].outerHTML = element[0].outerHTML.replace('%url%',attrs.iframeSrc); console.log(element); } }; <div ng-app="myApp"> <div>display google in frame</div> <my-frame data-iframe-src="http://jsfiddle.net">test</my-frame> </div> console.log (elemento); return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe src="%url%" height="100%" width="100%" frameborder="0"></iframe>', compile: function (element, attrs, transclude) { console.log(element[0].outerHTML); element[0].outerHTML = element[0].outerHTML.replace('%url%',attrs.iframeSrc); console.log(element); } }; <div ng-app="myApp"> <div>display google in frame</div> <my-frame data-iframe-src="http://jsfiddle.net">test</my-frame> </div> } return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe src="%url%" height="100%" width="100%" frameborder="0"></iframe>', compile: function (element, attrs, transclude) { console.log(element[0].outerHTML); element[0].outerHTML = element[0].outerHTML.replace('%url%',attrs.iframeSrc); console.log(element); } }; <div ng-app="myApp"> <div>display google in frame</div> <my-frame data-iframe-src="http://jsfiddle.net">test</my-frame> </div> }; return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe src="%url%" height="100%" width="100%" frameborder="0"></iframe>', compile: function (element, attrs, transclude) { console.log(element[0].outerHTML); element[0].outerHTML = element[0].outerHTML.replace('%url%',attrs.iframeSrc); console.log(element); } }; <div ng-app="myApp"> <div>display google in frame</div> <my-frame data-iframe-src="http://jsfiddle.net">test</my-frame> </div> <div ng-app = "myApp"> return { restrict: 'E', require: '?ngModel', replace: true, transclude: true, template: '<iframe src="%url%" height="100%" width="100%" frameborder="0"></iframe>', compile: function (element, attrs, transclude) { console.log(element[0].outerHTML); element[0].outerHTML = element[0].outerHTML.replace('%url%',attrs.iframeSrc); console.log(element); } }; <div ng-app="myApp"> <div>display google in frame</div> <my-frame data-iframe-src="http://jsfiddle.net">test</my-frame> </div> 
    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.