Javascript 如何在咖啡脚本和角度中具有可观察性
我正在使用Angular.js和CoffeeScript。我在控制器中有一个名为Current Page的变量。当前页面已绑定到文本框。当用户更改当前页面的值时,如何在控制器中触发方法调用。例如,当前页面的值为5。当用户更改它时,我想在Angular中调用控制器中的方法。我该怎么做Javascript 如何在咖啡脚本和角度中具有可观察性,javascript,angularjs,coffeescript,Javascript,Angularjs,Coffeescript,我正在使用Angular.js和CoffeeScript。我在控制器中有一个名为Current Page的变量。当前页面已绑定到文本框。当用户更改当前页面的值时,如何在控制器中触发方法调用。例如,当前页面的值为5。当用户更改它时,我想在Angular中调用控制器中的方法。我该怎么做 提前感谢 您可以在控制器中使用$scope.$watch. $scope.currentPage = 1; $scope.$watch('currentPage', function() {
提前感谢 您可以在控制器中使用
$scope.$watch.
$scope.currentPage = 1;
$scope.$watch('currentPage', function() {
alert('hey, currentPage has changed!');
}, true);
签出并我使用了ng blur并在控制器中调用了一个方法。使用$scope.$监视它在用户输入时激发。因此使用了模糊
<input type="text" ng-model="controller.currentPage" ng-blur="controller.handlePageChange()" class="form- control"/><span>Of</span>
的
在控制器中,我有:
handlePageChange:=>
if (this.currentPage != this.data.currentPage) && (this.currentPage >= 1 && this.currentPage <= this.data.maxPages())
console.log 'The page has indeed changed'
this.data.paginate(this.currentPage)
handlePageChange:=>
如果(this.currentPage!=this.data.currentPage)&&&(this.currentPage>=1&&this.currentPage)感谢您的回复。这为我提供了正确的工作方向。