$scope变量中的元素won'
element in my $scope variable won't get display
我刚刚部署了一个网站在"生产"中进行测试,但是当我试图访问该网站时,我的一些计算机不会看到我的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 post对象的数组。然后我像这样做一个q:
$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中的每个任务。所有问题都得到了解决。我在我的HTML中看到它们,比如分类、制造商等。结果[2]是帖子数组,它不是空的,其中确实有500个帖子。我尝试在buildGallery()方法调用后调用$scope.$apply(),但没有任何工作。如果我打印{{posts}}在我的html的任何地方,我看到的帖子数组。但是当他们在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也许问题会发生在你的电脑上。我试了火狐、火狐开发版、edge版、chrome和IE11。
谢谢。
我发现这是adblock谁没有显示我的div作为类"ad-container"。所以css中所有包含"ad"的类
相关文章:
- CKEditor Widget-阻止编辑可编辑元素本身
- 如何设置html元素填充的动画
- 如何将HTML id分配给元素,以及如何将JavaScript应用于元素
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- 使用clickToggle并在单击另一个元素时关闭元素
- 单击时将焦点更改为元素
- 表追加而不附加最后一个元素
- 如何在jQuery中获取元素的形式
- 我可以获得相对于被点击元素的确切点击位置吗
- 在函数中添加数组元素的数值
- 在单击任何位置时隐藏元素,而不检查每次DOM单击
- 将视口底部滚动到元素底部
- 是否有任何snippet或jQuery插件可以列出easylist.txt模式匹配的DOM中的所有元素
- 在不使用JQuery的情况下隐藏DOM中的选定元素
- 使用硒.硒中的元素1 won't使用jQuery检测附加到DOM的元素
- 新增元素使用delegate() won't bind jscolor.js
- JQuery won't选择追加的隐藏元素
- JS函数won't hide元素
- $scope变量中的元素won'
- d3.style won't设置HTML元素的宽度