2017-07-26 5 views
0

https://jsfiddle.net/BRNTZN/05c1agtb/18/

HTML:

<html> 
<head> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.6/angular.min.js"></script> 
    <script src="myapp.js"></script> 
</head> 
<body ng-app="myapp"> 
    <div ng-controller="mainctrl"> 
     {{query}} 
     <iframe ng-src="https://www.google.be/search?q={{query}}"></iframe> 
    </div> 
</body> 
</html> 

JS:

var app = angular.module('myapp', []); 

app.config(function($sceDelegateProvider) { 
    $sceDelegateProvider.resourceUrlWhitelist([ 
    'self', 
    'https://www.google.be/**' 
    ]); 
}); 

app.controller('mainctrl', function MainController($scope) { 
    $scope.query = "javascript"; 
}); 

Wenn die oben außerhalb der Geige zu tun bekomme ich folgende js Fehler in der Konsole:

Error: [$interpolate:noconcat] http://errors.angularjs.org/1.5.6/$interpolate/noconcat?p0=https%3A%2F%2Fwww.google.be%2Fsearch%3Fq%3D%7B%7Bquery%7D%7D 
    at angular.js:38 
    at Function.Ka.throwNoconcat (angular.js:11887) 
    at k (angular.js:12193) 
    at ha (angular.js:9606) 
    at $b (angular.js:8553) 
    at s (angular.js:8378) 
    at s (angular.js:8394) 
    at s (angular.js:8394) 
    at aa (angular.js:8281) 
    at angular.js:1782 

Wenn das der Link führt zu folgenden Erklärung:

Error while interpolating: https://www.google.be/search?q={{query}} 
Strict Contextual Escaping disallows interpolations that concatenate multiple expressions when a trusted value is required. See http://docs.angularjs.org/api/ng.$sce 

was sehr seltsam ist, weil ich bin Whitelisting „https://www.google.be/ **“, wie meine Geige belegt.

Warum hat die Whitelist keine Wirkung?

Antwort

0

Ich glaube nicht, dass ng-src mit $ sce arbeitet. Ändern der ng-src zu ng-bind-html in der Geige funktioniert.

<iframe ng-bind-html="https://www.google.be/search?q={{query}}"></iframe> 

https://jsfiddle.net/05c1agtb/19/

+0

das macht in der Tat die richtige HTML erscheinen, jedoch wird der iframe überhaupt nicht wiedergegeben. Ich habe versucht, https://en.wikipedia.org/wiki/{{query}}, die eigentlich eine bessere Seite ist, um Iframes mit zu testen. Die Google One rendert nie in einem iframe. – BRNTZN

Verwandte Themen