【问题标题】:How to update view angularjs from data server (api/nodejs/mongodb) by click如何通过单击从数据服务器(api/nodejs/mongodb)更新视图 angularjs
【发布时间】:2017-09-15 17:12:52
【问题描述】:

我想知道如何在使用 ng-click 更新后从数据服务器更新视图。

我使用 Daftmonk 均值堆栈生成器。

我用代码打开了另一个主题但没有答案,也许我走错路了update/refresh angularjs ng-repeat with data from server

【问题讨论】:

    标签: angularjs node.js mongodb express angularjs-ng-repeat


    【解决方案1】:

    查看 $watch 和 $apply

    $watch 将监视更改并使用按钮调用 $apply

    function MyController($scope) {
    
       $scope.myVar = 1;
    
       $scope.$watch('myVar', function() {
           alert('hey, myVar has changed!');
       });
    
       $scope.changeValueButton = function() {
          $scope.myVar = 2; // This will trigger $watch expression to kick in
       };
    
       $scope.updateButton = function() {
          $scope.apply();
       };
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-11-27
      • 2012-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-03
      相关资源
      最近更新 更多