search

Home  >  Q&A  >  body text

angular.js - angularjs ng-repeat 不能刷新

如图,我直接push数组是可以正常刷新页面的。但是如果我将一个新数组直接赋值个$scope.items就不是刷新页面了。

阿神阿神2744 days ago548

reply all(4)I'll reply

  • PHPz

    PHPz2017-05-15 16:59:36

    The answer is in the comments

    You are using Angular, use promises:

    // in your service
    
    function getSp() {
      return $http.get(apiHost)
    }
    // in your controller
    
    $scope.items = ckGL.getSp().then(response => response[0])

    That’s what I mean, you can add logs or something depending on the situation

    reply
    0
  • PHP中文网

    PHP中文网2017-05-15 16:59:36

    The main topic is to transfer the scope of the Controller to the Service. It is better to get the methods of the Service to the Controller.
    For example:

    $scope.getSp = ckGl.getSp
    $scope.getSp($scope.items)

    reply
    0
  • 天蓬老师

    天蓬老师2017-05-15 16:59:36

    After assigning the value, console the value of $scope.items to see if you have paid the wrong value... It is difficult to know where your problem is just by writing it like this. Normally it will trigger rendering

    reply
    0
  • phpcn_u1582

    phpcn_u15822017-05-15 16:59:36

    Because in js, object assignment is a reference, ng monitoring can be understood as address monitoring, so if the original array remains unchanged, ngrepeat will not be triggered

    reply
    0
  • Cancelreply