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";
});
時做上述小提琴之外,我得到在控制檯下面JS錯誤:
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
當鏈接指向下面的解釋:
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
這是非常奇怪的,因爲我的白名單「https://www.google.be/ **」我的小提琴就是明證。
爲什麼白名單中沒有什麼影響?
這確實做出正確的HTML出現,但是IFrame不再呈現在所有。我試着用https://en.wikipedia.org/wiki/{{query}}這實際上是一個更好的頁面來測試I幀。谷歌的一個不會在iframe中呈現。 – BRNTZN