GVKun编程网logo

AngularJS:清除$ watch(angular清缓存)

13

想了解AngularJS:清除$watch的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于angular清缓存的相关问题,此外,我们还将为您介绍关于AngularJS$watchvs$wat

想了解AngularJS:清除$ watch的新动态吗?本文将为您提供详细的信息,我们还将为您解答关于angular清缓存的相关问题,此外,我们还将为您介绍关于AngularJS $ watch vs $ watchCollection:哪个性能更好?、AngularJS $watch vs $watchCollection:这是更好的性能?、AngularJS $watch 的 Angular 等价物是什么?、AngularJS $watchFn的新知识。

本文目录一览:

AngularJS:清除$ watch(angular清缓存)

AngularJS:清除$ watch(angular清缓存)

我的AngularJS应用程序中具有监视功能。

$scope.$watch('quartzCrystal',function () {
   ...
}

但是,在某些情况下(在我的示例中,更改了我的单页应用程序的页面),我想停止监视(例如清除超时)。

我怎样才能做到这一点?

AngularJS $ watch vs $ watchCollection:哪个性能更好?

AngularJS $ watch vs $ watchCollection:哪个性能更好?

为了观看对象作用域变量,将$scope.$watchobjectEquality设置为true还是$scope.$watchCollection更好?

对于一个$scope对象变量(如15点的属性,一些嵌套2级深)与输入元件和更新ng- model在视图中,有多差$scope.$watchobjectEquality设定为true?这是要避免的大事吗?

$watchCollection一个更好的解决方案?

我正在寻找轻松的方式来提高AngularJS应用程序的性能(我仍然停留在v1.2.2上)。

  // ctrl scope var
  $scope.filters = {
    name: '',info: {test: '',foo: '',bar: ''},yep: ''
    // etc ...
  }

  // ctrl watch ?
  $scope.$watch('filters',function(newVal,oldVal) {
    if(newVal !== oldVal) {
      // call with updated filters
    }
  },true);

  // or ctrl watch collection ?
  $scope.$watchCollection('filters',oldVal) {
    if(newVal !== oldVal) {
      // call with updated filters
    }
  });

  // view input with ng-model
  <input type="text" ng-model="filters.name" />
  <input type="text" ng-model="filters.info.test" />
  <input type="text" ng-model="filters.yep" />
  // etc ...

AngularJS $watch vs $watchCollection:这是更好的性能?

AngularJS $watch vs $watchCollection:这是更好的性能?

对于观察对象范围变量,是$ scope。$ watch with objectEquality设置为true OR $ scope。$ watchCollection更好?

对于一个$ scope对象变量(如15个属性,一些嵌套的2级深度)用视图中的输入元素和ng-model更新,$ scope有多糟糕$ watch with objectEquality设置为true?这是一件值得避免的事吗?

是$ watchCollection更好的解决方案吗?

我正在寻找容易的胜利,以提高我的AngularJS应用程序的性能(我仍然坚持在v1.2.2)。

// ctrl scope var
  $scope.filters = {
    name: '',info: {test: '',foo: '',bar: ''},yep: ''
    // etc ...
  }

  // ctrl watch ?
  $scope.$watch('filters',function(newVal,oldVal) {
    if(newVal !== oldVal) {
      // call with updated filters
    }
  },true);

  // or ctrl watch collection ?
  $scope.$watchCollection('filters',oldVal) {
    if(newVal !== oldVal) {
      // call with updated filters
    }
  });

  // view input with ng-model
  <input type="text" ng-model="filters.name" />
  <input type="text" ng-model="filters.info.test" />
  <input type="text" ng-model="filters.yep" />
  // etc ...

The $watchCollection() function is a sort-of mid-ground between the
two $watch() configurations above. It’s more in-depth than the
vanilla $watch() function; but,it’s not nearly as expensive as the
deep-equality $watch() function. Like the $watch() function,the
$watchCollection() works by comparing physical object references;
however,unlike the $watch() function,the $watchCollection() goes
one-level deep and performs an additional,shallow reference check of
the top level items in the collection.

see this explanation

AngularJS $watch 的 Angular 等价物是什么?

AngularJS $watch 的 Angular 等价物是什么?

在 AngularJS 中,您可以$watch使用$scope. 在 Angular 中观察变量变化(例如,在组件变量中)的等价物是什么?

AngularJS $watchFn

AngularJS $watchFn

$watchFn(watchFn,watchAction,deepWatch);

watchFn :该参数是一个带有Angular表达式或者函数的字符串,他会返回被监控的数据模型的当前值,这个表达式将会被执行很多次,所以你要班长不会产生副作用,被调用多次而不会改变状态。 watchAction:这是一个函数或者表达式,当watchFn发生变化是会被调用。如果是函数的形式,他将会接受到watchFn的新旧两个值,以及作用域对象的引用。起函数签名为function(newValue,oldValue,scope). deepWatch:如果设置为true,这个可选的布尔型参数将会命令Angular去检查被监控对象的每一个熟悉是否发生变化

$watch函数会返回一个函数,当你不再需要接受变更通知是,可以用这个返回的函数注销。

今天关于AngularJS:清除$ watchangular清缓存的介绍到此结束,谢谢您的阅读,有关AngularJS $ watch vs $ watchCollection:哪个性能更好?、AngularJS $watch vs $watchCollection:这是更好的性能?、AngularJS $watch 的 Angular 等价物是什么?、AngularJS $watchFn等更多相关知识的信息可以在本站进行查询。

本文标签: