如何使用Angular动态添加iframe-src
How to dynamically add an iframe src with Angular
我遇到了一个Error: $interpolate:interr Interpolation Error
,它动态地将youtube视频放入iframe中。
html
<div class="embed-responsive embed-responsive-16by9">
<iframe class="embed-responsive-item" src="{{youtubeVideo}}" allowfullscreen></iframe>
</div>
Javascript/Angular
$http({
method: 'GET',
url: getTankVideos(query)
}).then(function successCallback(response) {
console.debug('response');
console.debug(response);
$scope.youtube = response;
console.log('Youtube');
console.log($scope.youtube);
console.log('Video Url');
$scope.youtubeVideo = 'https://www.youtube.com/watch?v=' + $scope.youtube.data.items[0].id.videoId;
console.log($scope.youtubeVideo);
}, function errorCallback(response) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
我的调试语句给了我有效的值
response
script.js:129 Object {data: Object, status: 200, config: Object, statusText: ""}
script.js:131 Youtube
script.js:132 Object {data: Object, status: 200, config: Object, statusText: ""}
script.js:134 Video Url
script.js:135 https://www.youtube.com/watch?v=BRtj_TSOHjw
为了安全起见,您需要在控制器中注入$sce
服务,并在其中注入trustAsResourceUrl url。
$scope.youtubeVideo = $sce.trustAsResourceUrl('https://www.youtube.com/watch?v=' + $scope.youtube.data.items[0].id.videoId);
相关文章:
- 如何使用Angular动态添加iframe-src
- 在不设置协议的情况下,使用javascript/jquery更改iframe-src
- 如何在使用JavaScript或jQuery刷新父页面后保留iframe-src
- Change iframe src
- 使用jQuery来foreach iframe-src,并通过函数获取ID和操作
- jQuery在iFrame Src中查找和替换文本
- 使用jQuery编辑iframe-src
- 如何更改具有相同类、名称的 iframe src
- 用vbscript更改iframe src(打开关于语言)
- iframe src 使用现有值在单击时添加自动播放=true 参数
- 为什么当我尝试为iframe-src属性构建URL时,AngularJS会抛出错误
- 防止iFrame src在加载时在单击时被触发
- 使用输入类型text更改iframe-src
- 更改iframe src可阻止父级隐藏
- 如何在访问时添加Iframe当前域
- 使用 JavaScript 更改 iframe src
- 使用jquery检测iframe-src更改
- 更改Vimeo Embed的iframe SRC添加到历史记录API
- 添加一个No Redirect到Iframe src使用javascript
- 添加javascript到iframe src属性