$scope变量中的元素won'

element in my $scope variable won't get display

本文关键字:won 元素 scope 变量      更新时间:2023-09-26

我刚刚部署了一个网站在"生产"中进行测试,但是当我试图访问该网站时,我的一些计算机不会看到我的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"的类