加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

在AngularJS中刷新iframe内容

发布时间:2020-12-17 07:59:09 所属栏目:安全 来源:网络整理
导读:我正在编写一个应用程序,它是Anugular和part jQuery的一部分.我通过在iFrame中加载jQuery内容来分离它们. 在某个事件(例如,点击一下)后,我需要刷新iFrame.我的控制器包含以下代码: $scope.resfeshIframe = function() { //refresh the iFrame with id "anIf
我正在编写一个应用程序,它是Anugular和part jQuery的一部分.我通过在iFrame中加载jQuery内容来分离它们.

在某个事件(例如,点击一下)后,我需要刷新iFrame.我的控制器包含以下代码:

$scope.resfeshIframe = function() { //refresh the iFrame with id "anIframe" };

而iFrame是:

<iframe id="anIframe" src="myUrl"></iframe>

有人可以帮助我.如果需要,我可以发布更多代码.

正如Paulo Scardine所说,正确的做法是通过指令 you shouldn’t use controllers to manipulate DOM.

像这样的东西可以做:

.directive('refreshable',[function () {
    return {
        restrict: 'A',scope: {
            refresh: "=refreshable"
        },link: function (scope,element,attr) {
            var refreshMe = function () {
                element.attr('src',element.attr('src'));
            };

            scope.$watch('refresh',function (newVal,oldVal) {
                if (scope.refresh) {
                    scope.refresh = false;
                    refreshMe();
                }
            });
        }
    };
}])

然后可以使用它,如:

<iframe refreshable="tab.refresh"></iframe>

而且:

$scope.refreshIframe = function(){
    $scope.tab.refresh = true;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读