Javascript ng src不会在url参数更改时更新iframe
我认为:Javascript ng src不会在url参数更改时更新iframe,javascript,angularjs,iframe,Javascript,Angularjs,Iframe,我认为: <iframe style="width: 100%;height: 240px;" scrolling="no" frameborder="0" ng-src="{{previewUrl}}"> </iframe> 在angular应用程序的生命周期中,测试在其他地方发生了更改,我希望iframe的源代码相应地更新 看起来,因为唯一的区别在于URL参数,所以angular忽略了更改 如果我将代码更改为: $scope.previewUrl = test ?
<iframe style="width: 100%;height: 240px;" scrolling="no" frameborder="0" ng-src="{{previewUrl}}">
</iframe>
在angular应用程序的生命周期中,测试在其他地方发生了更改,我希望iframe的源代码相应地更新
看起来,因为唯一的区别在于URL参数,所以angular忽略了更改
如果我将代码更改为:
$scope.previewUrl = test ? '/foo/bar/' : '/foo/bar/baz/';
一切正常
这是angularjs中的错误还是我遗漏了什么?
我正在使用angular版本1.2.5我想您可能需要使用
$sce.trustAsResourceUrl
使其正常工作
根据你的例子,你需要做的改变是
$scope.previewUrl = $sce.trustAsResourceUrl(test ? '/foo/bar/' : '/foo/bar/baz/');
HTH我想您可能需要使用
$sce.trustAsResourceUrl
使其工作
根据你的例子,你需要做的改变是
$scope.previewUrl = $sce.trustAsResourceUrl(test ? '/foo/bar/' : '/foo/bar/baz/');
HTH使用“$sce”服务解决您的问题,如下所示
// in Controller
app.controller('TestWorkController', function ($scope, $sce) {
$scope.previewUrl = $sce.trustAsResourceUrl(true ? 'http://clips.vorwaerts-gmbh.de/VfE.webm' : 'http://www.quirksmode.org/html5/videos/big_buck_bunny.webm');
});
//View
<iframe style="width: 100%;height: 240px;" scrolling="no" frameborder="0" ng-src="{{previewUrl}}"></iframe>
//在控制器中
app.controller('TestWorkController',函数($scope,$sce){
$scope.previewUrl=$sce.trustAsResourceUrl(true?)http://clips.vorwaerts-gmbh.de/VfE.webm' : 'http://www.quirksmode.org/html5/videos/big_buck_bunny.webm');
});
//看法
使用“$sce”服务解决您的问题,如下所示
// in Controller
app.controller('TestWorkController', function ($scope, $sce) {
$scope.previewUrl = $sce.trustAsResourceUrl(true ? 'http://clips.vorwaerts-gmbh.de/VfE.webm' : 'http://www.quirksmode.org/html5/videos/big_buck_bunny.webm');
});
//View
<iframe style="width: 100%;height: 240px;" scrolling="no" frameborder="0" ng-src="{{previewUrl}}"></iframe>
//在控制器中
app.controller('TestWorkController',函数($scope,$sce){
$scope.previewUrl=$sce.trustAsResourceUrl(true?)http://clips.vorwaerts-gmbh.de/VfE.webm' : 'http://www.quirksmode.org/html5/videos/big_buck_bunny.webm');
});
//看法