Angularjs: call other scope which in iframe

前端 未结 4 2235
清酒与你
清酒与你 2020-11-27 13:44

In my test, given 2 document, A and B. In A document, there is an iframe, the iframe source is B document. My question is how to modify B document certain scope of variable?

4条回答
  •  清酒与你
    2020-11-27 14:25

    This one is quite simple and works for me:

    in the controller code of iframe page:

    $window.parent.window.updatedata($scope.data);
    

    in the parent page controller code:

    window.updatedata = function (data) {
     $scope.$apply(function () {
         $scope.data = data
       }
     }
    

提交回复
热议问题