Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/374.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在咖啡脚本和角度中具有可观察性_Javascript_Angularjs_Coffeescript - Fatal编程技术网

Javascript 如何在咖啡脚本和角度中具有可观察性

Javascript 如何在咖啡脚本和角度中具有可观察性,javascript,angularjs,coffeescript,Javascript,Angularjs,Coffeescript,我正在使用Angular.js和CoffeeScript。我在控制器中有一个名为Current Page的变量。当前页面已绑定到文本框。当用户更改当前页面的值时,如何在控制器中触发方法调用。例如,当前页面的值为5。当用户更改它时,我想在Angular中调用控制器中的方法。我该怎么做 提前感谢 您可以在控制器中使用$scope.$watch. $scope.currentPage = 1; $scope.$watch('currentPage', function() {

我正在使用Angular.js和CoffeeScript。我在控制器中有一个名为Current Page的变量。当前页面已绑定到文本框。当用户更改当前页面的值时,如何在控制器中触发方法调用。例如,当前页面的值为5。当用户更改它时,我想在Angular中调用控制器中的方法。我该怎么做


提前感谢

您可以在控制器中使用
$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)感谢您的回复。这为我提供了正确的工作方向。