Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/394.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 ng加载时不重复渲染_Javascript_Angularjs - Fatal编程技术网

Javascript ng加载时不重复渲染

Javascript ng加载时不重复渲染,javascript,angularjs,Javascript,Angularjs,我有一个页面通过http.get从请求的数据中呈现ng repeat,但是它没有从get请求加载数据。我错过了什么 HTML: 您应该将获取图像的get请求包含在函数中并调用它。这将确保imgs阵列包含图像数据 angular.module('imginterestApp') .controller('GuestPageCtrl',函数($scope、$routeParams、$http){ $scope.userName=$routeParams.userId; log($scope.use

我有一个页面通过http.get从请求的数据中呈现ng repeat,但是它没有从get请求加载数据。我错过了什么

HTML:


您应该将获取图像的get请求包含在函数中并调用它。这将确保imgs阵列包含图像数据

angular.module('imginterestApp')
.controller('GuestPageCtrl',函数($scope、$routeParams、$http){
$scope.userName=$routeParams.userId;
log($scope.userName);
$scope.imgs=[];
$scope.init=函数(){
$http.get('/api/images/').success(函数(数据){
data.forEach(函数(图像){
if(image.owner==$scope.userName){
$scope.imgs.push(图像);
}
})
log($scope.imgs);
});
}
$scope.init();

});如果(image.owner==$scope.userName)…这是什么…@vijaykani我正在通过将所有者名称与传递的参数匹配来过滤用户图像。经过几次测试后,该函数运行良好。我遇到的问题是ng-repeat.is在控制台中为您的
console.log($scope.imgs)显示了一些东西?这意味着作用域中实际上有项目吗?请尝试在图像推送后添加$scope.$apply(),以强制手动更新。@vonv。是的,很好。
<div class="container-fluid" ng-show="isLoggedIn()">
<div class="row images">
    <div class="col-md-8 col-md-offset-2">
        <div class="row">
            <div class="col-xs-6 col-md-4" ng-repeat="img in imgs">
                <div class="thumbnail">
                    <img src="{{img.url}}">
                </div>
            </div>
        </div>
    </div>
</div>
angular.module('imginterestApp')
  .controller('GuestPageCtrl', function ($scope, $routeParams, $http) {
    $scope.userName = $routeParams.userId;
    console.log($scope.userName);
    $scope.imgs = [];

    $http.get('/api/images/').success(function(data){
        data.forEach(function(image){
        if(image.owner === $scope.userName) {
          $scope.imgs.push(image);
        }
      })
      console.log($scope.imgs);
    });
  });