Angularjs 如何在没有$watch的情况下更新$scope值以进行交叉更新

Angularjs 如何在没有$watch的情况下更新$scope值以进行交叉更新,angularjs,angularjs-scope,Angularjs,Angularjs Scope,我需要两个对象的交叉更新值 $scope.price = 0 $scope.amount = 1 $scope.total = 0 $scope.$watch('price', function(){ $scope.total = parseFloat( $scope.price * $scope.amount ).toFixed(2); }) $scope.$watch('total', function(){ $scope.price = parseFloat( $scope.t

我需要两个对象的交叉更新值

$scope.price = 0
$scope.amount = 1
$scope.total = 0

$scope.$watch('price', function(){
  $scope.total = parseFloat( $scope.price * $scope.amount ).toFixed(2);
})

$scope.$watch('total', function(){
  $scope.price = parseFloat( $scope.total / $scope.amount ).toFixed(2);
})
当我从$watch函数更新值时,我需要禁用$watch,可能类似于setViewValue

我能做什么


问题是:如何在不使用摘要跳过$watch函数的情况下更新$scope值?

如果您查看此处的$watch部分:

返回

函数返回此侦听器的注销函数

因此:


谢谢你的回答,但这不是我需要的。我只想在$watch函数中设置$scope.total或$scope.price的新值,而不调用任何$watch侦听器,而是更新视图。我不知道如何解释这个更简单。你不能用我的代码禁用手表,更新值,然后重新启用手表?是的,但这太奇怪了。为什么Angular团队不使用$scope.$setViewValue'price',222或$scope.$skipDigest这样简单的方法呢。。。
var disabler = $scope.$watch('price', function(){
  $scope.total = parseFloat( $scope.price * $scope.amount ).toFixed(2);
})

//this will de-register the watch
disabler();