绑定角度交叉内部框架,可能吗? [英] Bind angular cross iframes, possible?

查看:76
本文介绍了绑定角度交叉内部框架,可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有什么办法可以绑定/股范围相同/控制器/指令和东西到另一个IFRAME在同一个域?

Is there any way you can bind/share the same scope/controllers/directives and stuff into another iframe in the same domain?

将是冷静,如果我能有相同的ngApp在另一个IFRAME以及。有没有人做过这样的事以前?

would be cool if i could have the same ngApp in another iframe aswell. Has anyone done anything like this before?

推荐答案

是的,它是可能的,你不需要做什么特别的,你只需要编译的内容。

Yes it is possible and you don't need to do anything special, you just need to compile the content.

下面是一个例子: http://jsfiddle.net/gWgYM/

Here is an example: http://jsfiddle.net/gWgYM/

HTML:

<div ng-app="app" ng-controller="test">
    <h1>The date is {{date}}</h1>
    <iframe frame=""></iframe>
</div>

的Javascript:

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

app.controller('test', function( $scope ) {
    $scope.date = new Date();
    window.setInterval(function() {
        $scope.date = new Date();
        $scope.$apply();
    }, 1000);
});

app.directive('frame', function( $compile ) {
    return function( $scope, $element ) {
        var $body = angular.element($element[0].contentDocument.body),
            template  = $compile('<p>The date in the iframe is {{date}}</p>')($scope);
        $body.append(template);
    };
});

这篇关于绑定角度交叉内部框架,可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆