Javascript 如何在getBoundingClientRect()中使用$watch

Javascript 如何在getBoundingClientRect()中使用$watch,javascript,angularjs,Javascript,Angularjs,我有一个iframe,当源更新到iframe时,基于加载时间(一些包含图像,因此加载需要时间)iframe ie的宽度和高度getBoundingClientRect()更改。因此,每次我想触发事件时,如何使用触发器使用$watch第一种方法: 可以使用$scope.$watch()查看函数 HTML 第二种方法: 变异观察者: MutationObserver接口提供监视DOM树更改的功能。() 快乐编码 请在这里粘贴一些代码,并提供plunker linkthnk you Ankit Pan

我有一个iframe,当源更新到iframe时,基于加载时间(一些包含图像,因此加载需要时间)iframe ie的宽度和高度<代码>getBoundingClientRect()更改。因此,每次我想触发事件时,如何使用触发器使用
$watch

第一种方法:

可以使用$scope.$watch()查看函数

HTML

第二种方法:

变异观察者: MutationObserver接口提供监视DOM树更改的功能。()


快乐编码

请在这里粘贴一些代码,并提供plunker linkthnk you Ankit Pandey:)它为MutationObserver编写了罚款+1$监视不适用于对DOM更改作出反应$监视表达式函数仅在框架摘要周期中调用。它们在响应DOM更改时不可靠。
<div ng-app="myApp" ng-controller="myCtrl">
   <div id="header">Example Header</div>
</div
var app = angular.module('myApp', []);
app.controller('myCtrl', function($scope) {
   let h = document.getElementById('header');

   $scope.$watch(function(){
      return h.getBoundingClientRect();
   }, function(newValue, oldValue){
      console.info("log", newValue, oldValue);
   });

});