在渲染视图之前加载数据

时间:2016-08-29 14:38:44

标签: angularjs

我正在使用我的控制器将图像加载到视图中。它工作正常,除了我加载视图时出现以下错误:

%7B%7Bimage.thumbnail%7D%7D:1 GET http://localhost:9000/%7B%7Bimage.thumbnail%7D%7D 404 (Not Found)

尽管有错误,它仍然有效,但我试图摆脱它。

以前是我以前做的事情:

控制器:

app.controller("WeddingGalerieCtrl", function($scope, $http) {

    $http.get(url)
    .then(function(response){
      $scope.images=response.data;
      console.log($scope.images);
    });

})

观点:

<ul class="list" >
  <li lightgallery class="list-item" ng-repeat="image in images">
    <a href="{{image.big}}">
      <img class="img-responsive" src="{{image.thumbnail}}" alt="" />
    </a>
  </li>
</ul>

我尝试添加一个解析函数,因此我的数据会在视图渲染之前加载,但我仍然有同样的错误。

  .when('/gallery/wedding', {
    templateUrl: 'views/gallery.html',
    controller: 'WeddingGalerieCtrl',
    css: ['../styles/galleries.css','../styles/lightgallery.css'],
    resolve: {
        images: function($http) {
            return $http.get(url).then(function(response) {
                return response.data;
            });
        }
    }
  })

app.controller("WeddingGalerieCtrl", function($scope, $http, images) {
  $scope.images = images;
})

1 个答案:

答案 0 :(得分:0)

我很愚蠢,我刚注意到我添加了src代码,而不是ng-src ...

相关问题