有棱角的带子在关闭时不会杀死观察者

angular-strap aside does not kill watcher when closed

本文关键字:观察者      更新时间:2023-09-26

我正在使用带有数据模板的角度带。

<button type="button" class="btn btn-lg btn-danger" data-template="aside/docs/aside.demo.tpl.html" data-placement="left" data-animation="am-slide-left" bs-aside="aside" data-container="body">
    Custom aside
    <br>
    <small>(using data-template)</small>
</button>

一切都很好。除此之外,每次旁白出现时,观看人数都在不断增加。关闭旁白时,观看者不会被扣除/删除。随着时间的推移,这会导致应用程序上的观察者不断累积。

如何在观察程序关闭时将其删除?

下面是一个关于如何解除watch:绑定的示例

var unbindWatcher = $scope.$watch('expression', function() {
    // When your aside is showing
    if (asideIsShowing) {
      // Unbind the watch
      unbindWatcher();
    }
  }
);