我刚刚部署了一个网站,以便在“生产”中进行测试,但是当我尝试访问该网站时,我的某些计算机将看不到我的ng-repeat结果,有些人会看到。如果我在没有显示任何内容的情况下访问网站,我会查看源代码,我会看到我的数组中每个对象的ng-repeat,但屏幕上没有html输出。我加载控制器时的一些代码:
/**
* Function that send a request to get a list of posts.
* @return {Function} A promise.
*/
function retrievePosts() {
var defered = $q.defer();
// If the user is logged in we do a search by country, otherwise we get all the posts.
if($rootScope.user !== null && $rootScope.user !== undefined) {
PostService.searchPost({ countries: [$rootScope.user.country] }, function(err, posts) {
if(err) {
defered.reject(err);
}
else if(posts && posts.length > 0) {
defered.resolve(posts);
}
// If the previous condition is not true, we try to get all the posts, since the search by country didn't work.
else {
PostService.getAllPosts(function(err, posts2) {
if(err) {
defered.reject(err);
} else {
defered.resolve(posts2);
}
});
}
});
} else {
PostService.getAllPosts(function(err, posts) {
if(err) {
defered.reject(err);
}
else {
defered.resolve(posts);
}
});
}
return defered.promise;
}
此函数用于获取JSON帖子对象的数组。然后我做了一个q.all这样:
$q.all([retrieveManufacturer(), retrieveCategories(), retrievePosts(), getTotalPosts(), retrieveGalleryPosts()]).then(function(results) {
$scope.manufacturers = results[0];
$scope.categories = results[1];
// Here we must cache the result and slice it, so that angular doesn't render
// a tone of post but 10 at a time.
postCache = results[2];
$scope.numberOfPostsToShow = 10;
$scope.posts = postCache.slice(0, $scope.numberOfPostsToShow);
// Some code to display the proper amount of post for each category.
var i = -1;
var max = results[3].length;
var groupedPostsCount = { };
var group;
while(++i < max) {
group = results[3][i];
// "_id" contains the name of the category.
groupedPostsCount[group._id] = group.count;
}
if(Object.keys(groupedPostsCount).length > 0){
$scope.categoriesPostCount = groupedPostsCount;
}
$scope.galleryPosts = results[4];
// Prepare the $scope.galleryPosts to be bound with posts.
buildGallery($scope.galleryPosts);
}, function(err) {
console.log(err);
});
$ q.all中的每个任务都会被执行并且它们都会得到解决。我在我的HTML中看到它们,如类别,制造商等...结果[2]这些帖子不是空的,他们确实有500个帖子。我尝试在buildGallery()方法调用之后调用$ scope。$ apply(),但没有任何效果。如果我在html中的任何地方打印{{posts}},我会看到一系列帖子。但是当他们进入ng-repeat时:
<div class="ad-container" ng-repeat="post in posts" ng-click="viewPostDetails(post)">
<div class="ad-picture">
<table class="wrapper">
<tr>
<td><img ng-src="img/175/{{ post.mainImageName || post.imgUrls[0] }}" alt="No image provided"/></td>
</tr>
</table>
</div>
<div class="ad-info">
<span class="ad-info-title">{{ post.title }}</span>
<span class="ad-info-price">{{ post.country == 'Canada' ? (post.price | currency : "CA$") : (post.price | currency : "US$") }}</span>
<br />
<span>{{ post.country }}, {{ post.province }}, {{ post.createdAt | date }}</span>
<p>{{ post.description }}</p>
</div>
</div>
当然这个代码在div中,有一个控制器绑定它。就像我说的,这真的很奇怪。在我的开发计算机上,一切都运行得很好,但是我朋友的一些计算机确实有效,有些则没有。这是www.firearmsbin.com网站的链接可能会在您的计算机上出现问题。我尝试使用firefox,firefox for dev,edge,chrome和IE11。
感谢。
答案 0 :(得分:0)
我发现adblock没有显示我的div作为“ad-container”类。因此,包含“ad”字的css中的每个类都会被阻止。