【发布时间】:2019-10-19 05:05:08
【问题描述】:
我正在研究 angularjs 应用程序,但我不明白为什么指令中的 $watch 只能在第一个参数中使用函数时按预期工作。
class PaginationController {
constructor($scope) {
"ngInject";
this.quantity = null;
this.$scope = $scope;
$scope.$watch(() => this.quantity, function (newValue, OldValue) {
console.log('new: ' + newValue);
console.log('old: ' + OldValue);
});
}
}
如果我只是使用 this.quantity 作为第一个参数 $watch 不要赶上变化。但是所有功能都按我的预期工作。有什么区别?
【问题讨论】:
标签: angularjs angularjs-directive watch